Skip to content

Commit 9606936

Browse files
authored
AsyncServiceBrowser must recheck for handlers to call when holding condition (#483)
- There was a short race condition window where the AsyncServiceBrowser could add to _handlers_to_call in the Engine thread, have the condition notify_all called, but since the AsyncServiceBrowser was not yet holding the condition it would not know to stop waiting and process the handlers to call.
1 parent 9c06ce1 commit 9606936

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

zeroconf/asyncio.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,15 @@ async def async_run(self) -> None:
209209
"""Run the browser task."""
210210
self.run()
211211
while True:
212-
if not self._handlers_to_call:
213-
# Wait for the type has the smallest next time
214-
next_time = min(self._next_time.values())
215-
now = current_time_millis()
216-
if next_time > now:
217-
await self.aiozc.async_wait(next_time - now)
212+
timeout = self._seconds_to_wait()
213+
if timeout:
214+
async with self.aiozc.condition:
215+
# We must check again while holding the condition
216+
# in case the other thread has added to _handlers_to_call
217+
# between when we checked above when we were not
218+
# holding the condition
219+
if not self._handlers_to_call:
220+
await wait_condition_or_timeout(self.aiozc.condition, timeout)
218221

219222
out = self.generate_ready_queries()
220223
if out:

0 commit comments

Comments
 (0)