fix: increase check time and add random wait to avoid service collisions by jpbede · Pull Request #1611 · python-zeroconf/python-zeroconf

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.