You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Darwin] Surface setup-payload parse failures instead of flattening to InvalidArgument
When ChipDnssdResolveNoLongerNeeded drops the consumer counter to zero we
were calling Finalize -> DNSServiceRefDeallocate immediately. Per the dnssd
contract, DNSServiceRefDeallocate discards any events already queued on
that connection but not yet read off the socket, so any inbound resolve
result that mDNSResponder had already written becomes invisible to us --
which manifests as a ~1s coldstart retry latency (the next resolve has to
start from scratch). A second observation from the mDNS owner is that
"starting and stopping queries doesn't query harder": a tight cancel-then-
restart pattern for the same instance name is strictly worse than letting
the existing query keep running.
This change introduces a deferred-teardown window (default 500ms) before
the actual DNSServiceRefDeallocate, gated by a per-ResolveContext
deferredTeardownScheduled flag. While the timer is armed:
- A queued read indicator that fires inside the window dispatches the
resolve result through the normal DispatchSuccess path, which
cancels the timer and finalizes the context naturally.
- A new ChipDnssdResolve for the same instance name reuses the
existing ResolveContext: it cancels the deferred-teardown timer,
bumps the consumer counter back to 1, and skips
DNSServiceCreateConnection / DNSServiceResolve entirely. This is
the coalescing half of the fix.
- If neither happens before the window elapses, the timer fires
OnResolveDeferredTeardown which calls Finalize(CHIP_ERROR_CANCELLED)
-- preserving the existing failure-path contract upper-layer state
machines (Discovery_ImplPlatform, MTRDevice CASE retry) rely on.
DispatchSuccess and DispatchFailure also cancel any pending teardown timer
so it can never fire against a freed context.
The window length is exposed via SetResolveDeferredTeardownDelay so the
new TestDarwinDnssdResolveCoalesce tests in TestDnssd.cpp can drive the
state machine in test time without waiting 500ms. Three tests cover:
- Resolve -> ResolveNoLongerNeeded -> Resolve within the window
reuses the same ResolveContext (counter 1 -> 0 -> 1).
- Wait > teardown delay with no new Resolve actually fires the
deferred teardown exactly once.
- The CHIP_ERROR_CANCELLED dispatch contract is preserved when no
0 commit comments