fn commit_slot_guard(
guard: &mut SessionSlotGuard<'_>,
sessions: &Cache<SessionId, SessionSlot>,
session_id: SessionId,
surb_admission: Arc<OnceLock<Arc<dyn SurbAdmissionControl>>>,
capacity: usize,
)Expand description
Commits guard, admitting session_id into the SURB store for capacity SURBs.
Free function rather than a method on SessionManager because the guard borrows the manager’s
cache, so a method would fight the same borrow the call sites are already inside. surb_admission
is passed separately for the same reason — the call sites hold &self while the guard holds the
cache borrow.
The slot is re-read from the cache rather than kept from allocation: the token admit returns has
to land in the cached copy of the slot, and that copy and the one the guard rolled in are two
clones of one value — see SessionSlot::claim_admission_token for why the cell they share is
behind an Arc. Re-reading is what keeps this honest when the cache has since handed the entry to
another reader: they all share the one cell.
An absent slot is not an error: the Session was established on this path, and commit runs with
None so the guard is still marked committed. The teardown that removed the slot already logged
“session closed”, so skipping the commit here would leave that close unpaired (see
SessionSlotGuard::commit).
A slot found by key that is not the one this establishment allocated is treated exactly like an
absent one, and for the same reason: the re-read is by a reusable pseudonym, so between this
Session’s SessionEstablished send and its parked commit a teardown can remove its slot and a
successor Session can be allocated under the same key. Admitting into the successor’s slot would
stamp the successor’s ring with this Session’s token, and the successor’s own commit would then
find the cell occupied and retire the successor’s live admission — dropping a running Session to
the quarantine, the failure this whole seam exists to prevent. The guard holds its own slot’s
AdmissionCell, so the re-read can reject a foreign slot by identity; the commit itself still
runs, since this Session was established.