◐ Shell
clean mode source ↗

feat: add reconfirm_record per RFC 6762 §10.4 by bluetoothbot · Pull Request #1772 · python-zeroconf/python-zeroconf

Summary

Add Zeroconf.reconfirm_record / async_reconfirm_record (and the
AsyncZeroconf wrapper) so callers can hint to the cache that a record
may be stale — e.g. when an application-level connect to a discovered
service fails. Implements the cache-flush-on-failure mechanism described
in RFC 6762 §10.4.

Closes #1413

Behaviour

  • async_reconfirm_record(record) schedules a background task and
    returns True if accepted, False if the record is not in the cache
    or a reconfirmation is already in flight (dedupes by cache entry).
  • The background task re-queries the record at t=0, 1s, 3s
    the §5.2 doubling-interval pattern and "two or more queries" minimum
    from §10.4.
  • If no fresh copy of the record lands in the cache by t=10s, the
    record is force-expired and listeners (e.g. ServiceBrowser) are
    notified through the same goodbye path used for TTL-zero responses.
  • reconfirm_record is the threadsafe variant for callers off the
    event loop.

Constants live in const.py (_RECONFIRM_QUERY_INTERVALS_MS,
_RECONFIRM_TIMEOUT_MS) with RFC citations next to them; please do not
tighten without an interop note.

Changes

  • Zeroconf.async_reconfirm_record / Zeroconf.reconfirm_record in _core.py
  • AsyncZeroconf.async_reconfirm_record in asyncio.py
  • Background reconfirm pipeline in RecordManager (_handlers/record_manager.py)
    plus .pxd updates for the new cdef public dict _reconfirm_tasks
    and the new cpdef entry point
  • Timing constants in const.py
  • README section explaining when callers should use it
  • tests/test_reconfirm.py (9 tests) and a quick_reconfirm_timing
    fixture in conftest.py

Test plan

  • pytest tests/test_reconfirm.py (9 passed)
  • pytest tests/ (404 passed, 2 skipped) — no regressions
  • ruff check src/ tests/ — clean
  • Cython rebuild of _handlers/record_manager.py succeeds (no
    closures inside cpdef)

Quality Report

Changes: 8 files changed, 331 insertions(+), 6 deletions(-)

Code scan: clean

Tests: passed (4 PASSED)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline