Commit 7978c8a
fix(mdns): DnssdNames discovery, staging, and TXT-parameter fixes (#3665)
* fix(mdns): run dependency pass even when filter accepts nothing
DnssdNames.#processMessage iterates a "dependency pass" after the filter
pass, attaching records whose names became known during message
processing (e.g. AAAA for an SRV target the SRV record just registered).
The loop guard `while (filteredBeforePass > filtered.size)` was checked
before the first iteration with `filteredBeforePass = records.length`
and `filtered.size = records.length`, so the body never ran for a
packet whose filter pass deleted nothing.
That's the common shape of a solicited A/AAAA-only response (e.g. the
follow-up `IpService` issues for a Matter SRV target hostname). The
records were dropped, `IpService.addresses` stayed empty, and
`CommissionableMdnsScanner` never delivered the device — manifesting as
intermittent commissioning failures (#524 on matterjs-server) where
`avahi-browse` showed the AAAA but matter.js logged hasAddresses: false.
Convert the loop to do/while so the dependency pass runs at least once.
Add a regression test that sends PTR+SRV in one packet, then A+AAAA
alone in a second, and asserts the records attach to the hostname.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* refactor(mdns): honour staged-record goodbyes outside the relevance gate
Goodbye (ttl=0) handling for staged A/AAAA records lived inside the
`if (packetRelevant)` block alongside staging, so a goodbye for a
hostname whose earlier A/AAAA was staged was silently dropped when its
packet carried nothing else we accept. The stale staged record then
got replayed on the next SRV that creates the hostname dependency.
Move goodbye eviction outside the gate and split staging-add from
goodbye-evict. Eviction is safe to run unconditionally because it only
operates on hostnames already present in `#stagedIpRecords` — entries
we ourselves admitted under the gate — so a noisy goodbye cannot poison
anything new.
Also drop an inline comment that just restated `Timer.utility`'s own
docstring, per the project's comment policy.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(mdns): clear stale TXT parameters when a record is removed or replaced
DnssdName.parameters was populated eagerly during installRecord and
never cleared when the underlying TXT record went away. A goodbye for
the TXT (or a replacement TXT that omits a key) left zombie entries in
the Map; downstream consumers reading `name.parameters` continued to
see values from earlier broadcasts even after the source record had
been removed.
Make `parameters` a derived view of the current TXT records:
recompute lazily from `#records` whenever the cache is invalidated, and
invalidate on every TXT install/delete. Tighten the getter return type
to `ReadonlyMap<string, string>` (and `DiscoveryData`'s parameter
likewise) so callers can't poison the cache.
Also fix `keyOf`'s in-place `record.value.sort()` for TXT records.
The mutation was previously hidden because the eager extract in
installRecord ran before keyOf and read wire order. Now that
parameters recomputes on demand from `record.value`, the sort would
silently reorder entries the next time the value array was iterated.
Add regression tests:
- "recomputes parameters when a TXT record is removed"
- "drops keys absent from a replacement TXT record"
Both attach an SRV alongside the TXT so the DnssdName itself is not
collected on TXT removal — that would mask the parameters-cleanup
behaviour.
Update the "discovers" test fixture to reflect the wire-preserved TXT
value order (was relying on the keyOf side effect).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent ad7c28a commit 7978c8a
5 files changed
Lines changed: 339 additions & 39 deletions
File tree
- packages
- general
- src/net/dns-sd
- test/net/dns-sd
- protocol/src/common
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
72 | 85 | | |
73 | 86 | | |
74 | 87 | | |
| |||
78 | 91 | | |
79 | 92 | | |
80 | 93 | | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
120 | 124 | | |
121 | 125 | | |
122 | 126 | | |
| |||
151 | 155 | | |
152 | 156 | | |
153 | 157 | | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
154 | 162 | | |
155 | 163 | | |
156 | 164 | | |
| |||
251 | 259 | | |
252 | 260 | | |
253 | 261 | | |
254 | | - | |
| 262 | + | |
| 263 | + | |
255 | 264 | | |
256 | 265 | | |
257 | 266 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | | - | |
110 | 109 | | |
111 | 110 | | |
112 | 111 | | |
| |||
213 | 212 | | |
214 | 213 | | |
215 | 214 | | |
216 | | - | |
217 | | - | |
218 | | - | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
219 | 218 | | |
220 | 219 | | |
221 | 220 | | |
| |||
224 | 223 | | |
225 | 224 | | |
226 | 225 | | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
227 | 251 | | |
228 | 252 | | |
229 | 253 | | |
| |||
232 | 256 | | |
233 | 257 | | |
234 | 258 | | |
| 259 | + | |
235 | 260 | | |
236 | 261 | | |
237 | 262 | | |
238 | 263 | | |
239 | 264 | | |
240 | 265 | | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | 266 | | |
258 | 267 | | |
259 | 268 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
| 98 | + | |
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
| |||
0 commit comments