Skip to content

fix: bound TC-deferral assembly window to first-arrival + max delay#1732

Draft
bluetoothbot wants to merge 1 commit into
python-zeroconf:masterfrom
bluetoothbot:koan/fix-issue-1726
Draft

fix: bound TC-deferral assembly window to first-arrival + max delay#1732
bluetoothbot wants to merge 1 commit into
python-zeroconf:masterfrom
bluetoothbot:koan/fix-issue-1726

Conversation

@bluetoothbot
Copy link
Copy Markdown
Contributor

@bluetoothbot bluetoothbot commented May 18, 2026

Summary

AsyncListener.handle_query_or_defer re-armed self._timers[addr] on every new TC packet, so a peer streaming truncated queries faster than the 400–500 ms random delay could slide the flush deadline forward indefinitely and keep the per-addr deferred list growing. RFC 6762 §18.5 frames that delay as a fixed reassembly budget starting at first arrival, not a sliding heartbeat.

The fix tracks first-arrival in _deferred_deadlines and caps each scheduled fire time at first_arrival + _TC_DELAY_RANDOM_INTERVAL[1]. If the next packet would push the timer past that deadline the existing TimerHandle is left in place so the queue still flushes on schedule.

Fixes #1726

Changes

  • _listener.py: add _deferred_deadlines slot, bound handle_query_or_defer reset at the per-addr deadline, clear it in _respond_query.
  • _listener.pxd: declare the new cython.dict and the locals used in the bounded path.
  • tests/test_core.py: regression test that pins random.randint to the max delay and asserts subsequent TC packets do not push _timers[addr].when() past the deadline established by the first packet.

Test plan

  • SKIP_CYTHON=1 poetry run pytest --timeout=60 tests/ — 359 passed, 2 skipped.
  • New tests/test_core.py::test_tc_bit_defer_window_is_bounded fails on master (timer slides forward) and passes with the fix.
  • poetry run ruff check and poetry run ruff format --check clean on the touched files.

Generated by Kōan /fix


Quality Report

Changes: 3 files changed, 65 insertions(+), 3 deletions(-)

Code scan: clean

Tests: passed (4 PASSED)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

A peer streaming truncated queries faster than the 400–500 ms random
delay used to rearm `_timers[addr]` could keep extending the flush
deadline indefinitely, so the per-addr deferred list never drained
(RFC 6762 §18.5 expects the window to be a fixed reassembly budget
starting at first arrival, not a sliding heartbeat).

Track first-arrival in `_deferred_deadlines` and cap each scheduled
fire time at `first_arrival + _TC_DELAY_RANDOM_INTERVAL[1]`. If the
next packet would push the timer past that deadline, leave the
existing TimerHandle in place so the queue flushes on schedule.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.76%. Comparing base (31194a3) to head (541fd8b).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1732   +/-   ##
=======================================
  Coverage   99.76%   99.76%           
=======================================
  Files          33       33           
  Lines        3440     3452   +12     
  Branches      473      476    +3     
=======================================
+ Hits         3432     3444   +12     
  Misses          5        5           
  Partials        3        3           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 18, 2026

Merging this PR will not alter performance

✅ 11 untouched benchmarks


Comparing bluetoothbot:koan/fix-issue-1726 (541fd8b) with master (31194a3)

Open in CodSpeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security: TC-deferral timer is rearmed on every new packet, giving an attacker unbounded growth window

1 participant