oliver-zehentleitner / maity
clean-up: limits and abuse: one waiter-per-key rule (the _holding copies) and one long-poll loop
tsk-javm686g22kx Open
From the clean-up audit tsk-hgnbapyw7hnh, Area 2 (Limits and abuse), read at 80647565. Line numbers are at 80647565; check each one against current main before changing it. Finding A2-5 of the audit.
This may also concern the security team: by reading the code (not reproduced), two waits of one key on one replica can both end as superseded, so a waiter may be dropped without an answer. Kept apart from the routine clean-up for that reason. No security card covers it.
1. "One waiter per key" exists twice, with different rules (design, possible bug)
routes/device_codes.py:57, 107-137androutes/notifications.py:42, 208-244each keep a_holding: dict[str, object]where the last arrival wins.longpoll.Registry.enter(longpoll.py:57-71) decides by the database start (started) instead. Its docstring says why arrival order is wrong: "a wait can reach this after a newer one of its key ... leaving neither".- The
_holdingwaits pass noon_starttowakeups.opened(device_codes.py:122), so their waiter'sstartedstays 0. - Proposal: give
wakeups.Heldthe waiter'ssupersededflag and passon_start, so_holdingcan go and both routes use the registry's rule. - First step: a test that starts two waits of one key on one replica and asserts that exactly one ends as superseded. If it passes today, say so on the card and treat the rest as clean-up.
2. The long-poll loop is copied (duplication)
routes/events.py:264-318androutes/runner.py:280-331hold the same loop:wakeups.opened,registry.enter, the superseded and disconnect checks,event.clear, read,stopping, the 2 s fallback (FALLBACK_SECONDS), thenleave. Onlyread, theendedcheck and the quiet pass differ.- Proposal: a
longpoll.hold(...)helper that owns the loop, withreadandquietpassed in, used by both routes (and by the two routes of item 1 once they use the registry).
Effort: M (both items). Risk: medium. Long-poll timing; run test_wakeups, test_event_quiet_passes and test_shutdown on PostgreSQL.
Order
- Item 1 before item 2.
- tsk-x1rsd4r6htcv (in review) changes what an events waiter does on a wake in
routes/events.py. Do item 2 after it.
Covered elsewhere
- None. Searched:
_holding,longpoll,wakeups.
Effort sum: 1M.