Skip to main content

Module holds

Module holds 

Source
Expand description

Holds on a task’s event log: the positions an attached stream still owes, which the log’s bound must not drop (spec §3.5.2: “Each stream MUST receive the same events in the same order”).

§Why this exists

A stream that falls behind its bounded broadcast buffer catches up from the task’s event log, after the last position it delivered. The in-memory stores bound that log (TaskStoreConfig::max_events_per_task, 512 by default) and drop the oldest event on every append past it, without asking whether a stream still owes it. Until 2026-10-20 a stream that fell more than 512 events behind therefore found the head of its catch-up gone and ended with streamLagged, though every event it missed had been in the log when it fell behind.

§What a hold does

A stream that reads from a store’s log takes an EventHold when it is built, at the position it starts after, and raises it (EventHold::advance) as it delivers. It owes every position above its mark, so the log may drop position s only when s is at or below the lowest mark on the task (EventHolds::floor). With no hold the log is trimmed exactly as before. Dropping the hold, which dropping the stream does, releases it; the log shrinks back to its bound on the next append, or, for a task that appends nothing more, at the store’s next eviction sweep.

§The ceiling, and what is still lost past it

A stream whose client stops reading but keeps the connection open would otherwise pin its task’s log for as long as the connection lasts. So a held log is bounded too, at max_held_events_factor times max_events_per_task (8 × 512 = 4,096 events by default). Past it the oldest event is dropped regardless, the store reports it (HOLD_CEILING), and the stream that owed it ends with the explicit streamLagged after what it delivered, as every stream past the bound did before. No stream skips an event silently.

§Concurrency

The registry is a std::sync::Mutex, separate from the store’s async RwLock, because a hold is taken while a stream is built and released in Drop, neither of which can await. The lock is held only for a map update and is never held across an .await. The store’s append takes it inside its own write lock; nothing takes them in the other order, so the two cannot deadlock. A mark is an atomic, so EventHold::advance takes no lock at all. A mark read while a stream advances it may be the older, lower value, which only keeps an event a little longer.

Structs§

EventHold
One stream’s hold on a task’s event log; see EventHolds.
EventHolds
The holds attached streams have on one store’s event logs, per task.

Constants§

DEFAULT_MAX_HELD_EVENTS_FACTOR
How many times max_events_per_task a task’s log may hold while an attached stream still owes its oldest events, when nothing else is asked for: 8, so 4,096 events at the default bound.