Repository navigation
Conversation
UnicastDnsSdClientProtocol previously finished as soon as it had received some reply for every outbound query packet, regardless of whether the reply content was complete. A device can take a moment after boot/wake to re-register a dynamic-port service (e.g. Companion) with its own mDNS responder, so this could close the socket before that service ever had a chance to answer. Completion now requires either every explicitly requested service to have answered (unambiguous, no wait needed), or the discovered service set to have gone unchanged for UNICAST_MIN_STABLE_ROUNDS consecutive rounds (reduces, doesn't eliminate, the risk of a still-registering service being missed), or the final resend round to be reached.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
UnicastDnsSdClientProtocol.datagram_receivedfinishes a scan as soon as it has received one response packet per query sent, regardless of whether all requested services actually appear in those packets. A device that's slow to re-register a dynamic-port service with its own mDNS responder (e.g. Companion right after boot/wake) can answer for everything else in round 1, causing the scan to close the socket immediately — before that service ever gets a chance to show up in a later round. The service isn't just "found late," it's never discovered for that scan at all.Fix
Track whether the set of discovered services is still growing round-to-round, and only finish early when:
UNICAST_MIN_STABLE_ROUNDS(2) consecutive rounds have passed with no new services appearing.An empty round never counts as "stable" on its own — that's just as likely to mean the device isn't ready yet as it is to mean nothing's coming. The common case (everything answers immediately) is unaffected — no added latency there.
Tests
Three new functional tests:
Context
Found this while chasing an intermittent bug in a small third-party bridge app talking to an Apple TV over Companion: on some connections Companion's power-state protocol was silently never active, and it traced back to this scan race dropping Companion during discovery. Fix has been running in production there for a few days with no repro of the original issue.
Possibly related (same
mdns.pyscan/discovery area, similar symptoms) but not something this PR claims to fix, since neither matches this exact mechanism: #2696 (multicast scan across subnets returning only a random subset of devices) and #2904 (identifier-based multicast discovery getting zero replies at all). Worth a look in case either turns out to share a root cause, but this fix is narrowly about the unicast resend loop finishing before a slow-to-register service appears.Diagnosis, fix, and tests written together with Claude Code (Anthropic).