Skip to main content

refund_quarantine_budget

Function refund_quarantine_budget 

Source
fn refund_quarantine_budget(budget: &AtomicUsize, n: usize)
Expand description

Subtracts n from the quarantine SURB budget, clamping at zero instead of wrapping.

Every refund site reads a ring length outside the ring’s own lock, so a stale reader can subtract SURBs that another site already accounted: with a bare fetch_sub, that interleaving drives the counter past zero and wraps it to near usize::MAX, after which counter + len > budget holds for every quarantine insert and the store refuses unadmitted ingress for good — a self-inflicted denial that no later drain can undo, because the drain subtracts rather than resets. Saturating keeps the design’s “no resync” stance (an over-refund still under-counts, which the cache’s own max_capacity bounds) while making the failure self-correcting: the counter bottoms out at zero and the next refund-free insert tops it back up.