Files
synapse/tests/synapse_rust
Erik JohnstonandClaude Opus 5 00c35955ee Move per-homeserver Rust state into a RustRuntime object on the HomeServer
Previously the tokio runtime was stashed in a hidden attribute on the
reactor object, installed lazily by whichever Rust code first needed it,
and started via callWhenRunning (which never fires under trial's
MemoryReactorClock, hence reactor.run() workarounds in several tests).

Instead, introduce:

* `Reactor`, a typed Rust wrapper around the Twisted reactor. The duck
  type is validated once at the FFI boundary, and the wrapper is the
  single place naming the Twisted API surface Rust relies on.
* `RustRuntime`, a frozen pyclass wrapping `Arc<RustRuntimeInner>`,
  constructed once per homeserver via `hs.get_rust_runtime()`. The tokio
  runtime starts lazily on first use; shutdown is driven by a reactor
  shutdown trigger holding only a `Weak` reference (so there is no
  uncollectable reference cycle through the Rust struct), with a `Drop`
  backstop for reactors whose triggers never fire.

Rust consumers (`HttpClient`, `VersionsHandler`, the Python DB pool
wrapper) now receive the runtime or reactor handle explicitly instead of
fishing state out of reactor attributes, and the reactor.run() /
manual-startup workarounds in tests are no longer needed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HyuiV3m44ZbK9o24EnMMES
2026-07-28 09:07:48 +00:00
..