Skip to content

fix: increase check time and add random wait to avoid service collisions - #1611

Merged
bdraco merged 4 commits into
python-zeroconf:masterfrom
jpbede:increase-checktime-random-wait
Sep 5, 2025
Merged

bdraco merged 4 commits into
python-zeroconf:masterfrom
jpbede:increase-checktime-random-wait

Conversation

@jpbede

@jpbede jpbede commented Sep 3, 2025 •

Copy link
Copy Markdown
Contributor

Problem

Service registration conflicts were occurring frequently on WiFi networks and with slow IoT devices. The probe responses from existing services weren't arriving within the default 175ms check window, causing false positives for available names and subsequent conflicts.

Solution

This PR improves mDNS service registration reliability by implementing two RFC 6762 recommended timing adjustments:

  1. Random startup delay (RFC 6762, Section 8.1): Added a random 150-250ms delay before sending the first probe query to avoid the "thundering herd" problem when multiple services start simultaneously

  2. Increased check interval: Extended _CHECK_TIME from 175ms to 500ms to accommodate slower WiFi and IoT devices while remaining RFC-compliant (the RFC specifies "should" for 250ms intervals, allowing flexibility for network conditions)

Changes

  • src/zeroconf/const.py: Increased _CHECK_TIME from 175ms to 500ms
  • src/zeroconf/_core.py: Added random 150-250ms initial delay before first probe (line 551)

Impact

  • Worst-case registration time: 1.75 seconds (250ms initial delay + 3×500ms checks)
  • Conflict detection reliability: Improved from ~10% to ~90% success rate on WiFi networks
  • RFC compliance: Maintains compliance while adapting to modern network realities where WiFi IoT devices are common

Testing

Verified with:

  • macOS dns-sd against Linux avahi-daemon
  • Conflict resolution triggers correctly after first QU (query unicast) response
  • Home Assistant startup with multiple services

Fixes service registration reliability issues reported when running development instances over WiFi.

@codspeed

codspeed Bot commented Sep 3, 2025 •

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #1611 will not alter performance

Comparing jpbede:increase-checktime-random-wait (8a1d57e) with master (02cc054)

Summary

✅ 6 untouched benchmarks

@codecov

codecov Bot commented Sep 3, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.76%. Comparing base (02cc054) to head (8a1d57e).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1611   +/-   ##
=======================================
  Coverage   99.76%   99.76%           
=======================================
  Files          33       33           
  Lines        3399     3401    +2     
  Branches      461      461           
=======================================
+ Hits         3391     3393    +2     
  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.

@bdraco

bdraco commented Sep 5, 2025

Copy link
Copy Markdown
Member

Tested on a few systems. Everything working as expected. It take a bit longer, but thats expected and worth the tradeoff.

@bdraco bdraco left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jpbede

@bdraco
bdraco merged commit 8c382ee into python-zeroconf:master Sep 5, 2025
@jpbede
jpbede deleted the increase-checktime-random-wait branch September 5, 2025 19:44

This branch had an error being deployed

1 failed deployment
release — 8a1d57e6 Deployed Sep 3, 2025 by jpbede
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.

2 participants