Skip to content

Commit fe86566

Browse files
authored
Don't call callbacks when holding _handlers_lock (#258)
Closes #255 Background: #239 adds the lock _handlers_lock: python-zeroconf/zeroconf/__init__.py self._handlers_lock = threading.Lock() # ensure we process a full message in one go Which is used in the engine thread: def handle_response(self, msg: DNSIncoming) -> None: """Deal with incoming response packets. All answers are held in the cache, and listeners are notified.""" with self._handlers_lock: And also by the service browser when issuing the state change callbacks: if len(self._handlers_to_call) > 0 and not self.zc.done: with self.zc._handlers_lock: handler = self._handlers_to_call.popitem(False) self._service_state_changed.fire( zeroconf=self.zc, service_type=self.type, name=handler[0], state_change=handler[1] ) Both pychromecast and Home Assistant calls Zeroconf.get_service_info from the service callbacks which means the lock may be held for several seconds which will starve the engine thread.
1 parent 54d116f commit fe86566

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

zeroconf/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,12 +1585,12 @@ def run(self) -> None:
15851585
if len(self._handlers_to_call) > 0 and not self.zc.done:
15861586
with self.zc._handlers_lock:
15871587
(name, service_type_state_change) = self._handlers_to_call.popitem(False)
1588-
self._service_state_changed.fire(
1589-
zeroconf=self.zc,
1590-
service_type=service_type_state_change[0],
1591-
name=name,
1592-
state_change=service_type_state_change[1],
1593-
)
1588+
self._service_state_changed.fire(
1589+
zeroconf=self.zc,
1590+
service_type=service_type_state_change[0],
1591+
name=name,
1592+
state_change=service_type_state_change[1],
1593+
)
15941594

15951595

15961596
class ServiceInfo(RecordUpdateListener):

0 commit comments

Comments
 (0)