Don't call callbacks whend holding _handlers_lock#258
Conversation
|
I need to wrap my head around why exactly does this help (for my own understanding), I'll have a longer look tomorrow unless someone beats me to it (@mattsaxon you're probably the best person to review this). |
|
One note to remember when merging this: it'll be nice to have the whole content of the original pull request comment in the commit message in master, it contains crucial information to understand this change. |
|
I think it's clear it's not good idea to hold the lock when calling
A reflection is that calling |
mattsaxon
left a comment
There was a problem hiding this comment.
This change looks good to me. Can I check that this is the only change that was needed to fix the whole issue being fixed as a number of patches were applied for testing purposes, have we backed those out and demonstrated this patch alone fixes the issue?
|
@mattsaxon: the other patches were:
Edit: thanks for reviewing and helping out with the issue! |
|
@emontnemery , did you determine if listening for the updates was required and therefore if there is another underlying bug in zeroconf that is needing to be investigated? |
|
There was always an add callback first in the logs. |
|
Yeah, I've just been looking at logs supplied by @hmmbob in #255 (comment) and there was always an |
|
This has just been released in 0.26.3, nice work everyone. |
One way to make this better could be to pass |
|
@emontnemery , regarding your reflection on fragility, can you elaborate? |
Don't hold
_handlers_lockwhen calling the service callbacks.Closes #255
Background:
#239 adds the lock
_handlers_lock:https://github.com/jstasiak/python-zeroconf/blob/552a030eb592a0c07feaa7a01ece1464da4b1d0b/zeroconf/__init__.py#L2209
Which is used in the engine thread:
https://github.com/jstasiak/python-zeroconf/blob/552a030eb592a0c07feaa7a01ece1464da4b1d0b/zeroconf/__init__.py#L2484-L2489
And also by the service browser when issuing the state change callbacks:
https://github.com/jstasiak/python-zeroconf/blob/552a030eb592a0c07feaa7a01ece1464da4b1d0b/zeroconf/__init__.py#L1541-L1546
Both pychromecast and Home Assistant calls
Zeroconf.get_service_infofrom the service callbacks which means the lock may be held for several seconds which will starve the engine thread.