@@ -150,6 +150,7 @@ func newClient() (*client, error) {
150
150
151
151
// Close is used to cleanup the client
152
152
func (c * client ) Close () error {
153
+ log .Printf ("[INFO] mdns: Closing client %v" , * c )
153
154
c .closeLock .Lock ()
154
155
defer c .closeLock .Unlock ()
155
156
@@ -158,7 +159,6 @@ func (c *client) Close() error {
158
159
}
159
160
c .closed = true
160
161
161
- log .Printf ("[INFO] mdns: Closing client %v" , * c )
162
162
close (c .closedCh )
163
163
164
164
if c .ipv4UnicastConn != nil {
@@ -243,6 +243,9 @@ func (c *client) query(params *QueryParam) error {
243
243
case * dns.PTR :
244
244
// Create new entry for this
245
245
inp = ensureName (inprogress , rr .Ptr )
246
+ if inp .complete () {
247
+ continue
248
+ }
246
249
247
250
case * dns.SRV :
248
251
// Check for a target mismatch
@@ -252,25 +255,37 @@ func (c *client) query(params *QueryParam) error {
252
255
253
256
// Get the port
254
257
inp = ensureName (inprogress , rr .Hdr .Name )
258
+ if inp .complete () {
259
+ continue
260
+ }
255
261
inp .Host = rr .Target
256
262
inp .Port = int (rr .Port )
257
263
258
264
case * dns.TXT :
259
265
// Pull out the txt
260
266
inp = ensureName (inprogress , rr .Hdr .Name )
267
+ if inp .complete () {
268
+ continue
269
+ }
261
270
inp .Info = strings .Join (rr .Txt , "|" )
262
271
inp .InfoFields = rr .Txt
263
272
inp .hasTXT = true
264
273
265
274
case * dns.A :
266
275
// Pull out the IP
267
276
inp = ensureName (inprogress , rr .Hdr .Name )
277
+ if inp .complete () {
278
+ continue
279
+ }
268
280
inp .Addr = rr .A // @Deprecated
269
281
inp .AddrV4 = rr .A
270
282
271
283
case * dns.AAAA :
272
284
// Pull out the IP
273
285
inp = ensureName (inprogress , rr .Hdr .Name )
286
+ if inp .complete () {
287
+ continue
288
+ }
274
289
inp .Addr = rr .AAAA // @Deprecated
275
290
inp .AddrV6 = rr .AAAA
276
291
}
@@ -288,7 +303,6 @@ func (c *client) query(params *QueryParam) error {
288
303
inp .sent = true
289
304
select {
290
305
case params .Entries <- inp :
291
- default :
292
306
}
293
307
} else {
294
308
// Fire off a node specific query
@@ -326,7 +340,13 @@ func (c *client) recv(l *net.UDPConn, msgCh chan *dns.Msg) {
326
340
return
327
341
}
328
342
buf := make ([]byte , 65536 )
329
- for ! c .closed {
343
+ for {
344
+ c .closeLock .Lock ()
345
+ if c .closed {
346
+ c .closeLock .Unlock ()
347
+ return
348
+ }
349
+ c .closeLock .Unlock ()
330
350
n , err := l .Read (buf )
331
351
if err != nil {
332
352
log .Printf ("[ERR] mdns: Failed to read packet: %v" , err )
0 commit comments