Skip to content

Commit d8caa4e

Browse files
mattsaxonjstasiak
authored andcommitted
Remove duplciate update messages sent to listeners
The prior code used to send updates even when the new record was identical to the old. This resulted in duplciate update messages when there was in fact no update (apart from TTL refresh)
1 parent 5e4f496 commit d8caa4e

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

zeroconf/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2431,8 +2431,15 @@ def handle_response(self, msg: DNSIncoming) -> None:
24312431
are held in the cache, and listeners are notified."""
24322432
now = current_time_millis()
24332433
for record in msg.answers:
2434+
2435+
updated = True
2436+
24342437
if record.unique: # https://tools.ietf.org/html/rfc6762#section-10.2
24352438
for entry in self.cache.entries():
2439+
2440+
if entry == record:
2441+
updated = False
2442+
24362443
if DNSEntry.__eq__(entry, record) and (record.created - entry.created > 1000):
24372444
self.cache.remove(entry)
24382445

@@ -2443,7 +2450,8 @@ def handle_response(self, msg: DNSIncoming) -> None:
24432450
maybe_entry.reset_ttl(record)
24442451
else:
24452452
self.cache.add(record)
2446-
self.update_record(now, record)
2453+
if updated:
2454+
self.update_record(now, record)
24472455
else:
24482456
if maybe_entry is not None:
24492457
self.update_record(now, record)

zeroconf/test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,7 @@ def mock_incoming_msg(service_state_change: r.ServiceStateChange) -> r.DNSIncomi
11251125
service_updated_event.clear()
11261126
service_text = b'path=/~humingchun/'
11271127
zeroconf.handle_response(mock_incoming_msg(r.ServiceStateChange.Updated))
1128+
zeroconf.handle_response(mock_incoming_msg(r.ServiceStateChange.Updated))
11281129
service_updated_event.wait(1)
11291130
assert service_added is True
11301131
assert service_updated_count == 2

0 commit comments

Comments
 (0)