Commit Graph
4 Commits
Author SHA1 Message Date
Erik JohnstonandClaude Opus 5 3b70d7c70a Add a clock to the Rust crate
Rust code increasingly needs the current time somewhere it cannot cheaply
ask Python for it: on a Tokio worker without the GIL, or deep inside a data
structure where reaching back out to a `synapse.util.clock.Clock` would mean
threading a `Py<PyAny>` through everything. Up to now there was no clock at
all in `rust/src` — the rendezvous handlers each held a `Py<PyAny>` and
called `time_msec()` on it per request.

Add `synapse::clock`, a wall clock matching `Clock.time_msec()` so times mean
the same thing on both sides of the boundary. It reads `SystemTime::now()`,
which on Linux is a vDSO call rather than a syscall.

Synapse's tests run against a virtual reactor clock, and it is important that
time in tests only moves when a test says so. The test reactor therefore pins
this clock to its own time; `tests.unittest.TestCase` unpins it afterwards so
it cannot leak between tests.

Port both rendezvous handlers over, which removes a Python round-trip per
rendezvous request and exercises the virtualisation against the existing
tests that drive session eviction by advancing the reactor.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HyuiV3m44ZbK9o24EnMMES
2026-07-27 10:53:27 +00:00
Erik JohnstonandGitHub 0dfcffab0f Fix looping calls not getting GCed. (#19416)
The `Clock` tracks looping calls to allow cancelling of all looping
calls. However, this stopped them from getting garbage collected.

This was introduced in https://github.com/element-hq/synapse/pull/18828

Fixes https://github.com/element-hq/synapse/issues/19392
2026-01-30 10:26:53 +00:00
Richard van der Hoff 1ea904b9f0 Use deferred.addTimeout instead of time_bound_deferred
This doesn't feel like a wheel we need to reinvent.
2018-04-23 00:53:18 +01:00
Richard van der Hoff b88a323ffb Fix time_bound_deferred to throw the right exception
Due to a failure to instantiate DeferredTimedOutError, time_bound_deferred
would throw a CancelledError when the deferred timed out, which was rather
confusing.
2017-03-23 12:07:11 +00:00