Expand description
Periodic sweep that DELs sessions whose bound client has been gone for
more than STALE_AFTER.
Sessions intentionally outlive their clients (Session no longer has a
belongs_to(Client) cascade) so the roster can show a brief
“disconnected” indicator across reconnect blips. Without this sweeper
that grace period would last forever — abandoned sessions would
accumulate in the registry and the on-disk log.
Tracking is in-memory: a disconnected_since map records the first
tick on which each session was observed disconnected. Daemon restart
resets it, which is fine — every session loaded from disk gets a fresh
10-second grace window before it can be swept, giving its shim time to
reconnect.
Constants§
- STALE_
AFTER - How long a session must be without a live client before it is DEL’d.
- TICK_
INTERVAL - How often the sweeper wakes up to check for stale sessions. Anything
roughly under
STALE_AFTERis fine; the trade-off is reaction latency (lower) vs. wake-ups per minute (higher).
Functions§
- run_
sweeper - Run the sweeper forever. Spawn this on a tokio task and forget it.