Skip to content

Commit 5504ee6

Browse files
committed
docs: explain TC-deferral fire-time sentinel and clamp returns
1 parent ac9c609 commit 5504ee6

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/zeroconf/_listener.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ def handle_query_or_defer(
211211
delay = millis_to_seconds(random.randint(*_TC_DELAY_RANDOM_INTERVAL)) # noqa: S311
212212
fire_at = self._compute_deferred_fire_at(addr, now, delay)
213213
if fire_at < 0.0:
214+
# Sentinel: a new reset would push the flush past the
215+
# per-addr reassembly deadline, so leave the existing
216+
# TimerHandle in place rather than re-arming it.
214217
return
215218
self._cancel_any_timers_for_addr(addr)
216219
self._timers[addr] = loop.call_at(
@@ -234,8 +237,14 @@ def _compute_deferred_fire_at(self, addr: _str, now: _float, delay: _float) -> _
234237
fire_at = now + delay
235238
if fire_at >= deadline:
236239
if addr in self._timers:
240+
# Existing timer already fires at or before the deadline;
241+
# signal the caller to leave it alone rather than reset it.
237242
return -1.0
243+
# First packet for this addr already proposes a fire-time at
244+
# or past the deadline — clamp to the deadline so the flush
245+
# still happens within the reassembly budget.
238246
return deadline
247+
# Within budget: schedule at the proposed fire-time.
239248
return fire_at
240249

241250
def _cancel_any_timers_for_addr(self, addr: _str) -> None:

0 commit comments

Comments
 (0)