Commit fe86566
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
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1585 | 1585 | | |
1586 | 1586 | | |
1587 | 1587 | | |
1588 | | - | |
1589 | | - | |
1590 | | - | |
1591 | | - | |
1592 | | - | |
1593 | | - | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
1594 | 1594 | | |
1595 | 1595 | | |
1596 | 1596 | | |
| |||
0 commit comments