mirror of
https://github.com/element-hq/synapse.git
synced 2026-08-15 15:40:47 +00:00
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