Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions tests/services/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,29 @@ def test_only_register_once(self):
registry.remove(info)
registry.add(info)

def test_unregister_multiple_times(self):
"""Verify we can unregister a service multiple times.

In production unregister_service and unregister_all_services
may happen at the same time during shutdown. We want to treat
this as non-fatal since its expected to happen and it is unlikely
that the callers know about each other.
"""
type_ = "_test-srvc-type._tcp.local."
name = "xxxyyy"
registration_name = "%s.%s" % (name, type_)

desc = {'path': '/~paulsm/'}
info = ServiceInfo(
type_, registration_name, 80, 0, 0, desc, "ash-2.local.", addresses=[socket.inet_aton("10.0.1.2")]
)

registry = r.ServiceRegistry()
registry.add(info)
self.assertRaises(r.ServiceNameAlreadyRegistered, registry.add, info)
registry.remove(info)
registry.remove(info)

def test_lookups(self):
type_ = "_test-srvc-type._tcp.local."
name = "xxxyyy"
Expand Down
2 changes: 2 additions & 0 deletions zeroconf/_services/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def _add(self, info: ServiceInfo) -> None:
def _remove(self, infos: List[ServiceInfo]) -> None:
"""Remove a services under the lock."""
for info in infos:
if info.key not in self._services:
continue
old_service_info = self._services[info.key]
self.types[old_service_info.type.lower()].remove(info.key)
self.servers[old_service_info.server_key].remove(info.key)
Expand Down