Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hold a strong reference to the query sender start task #1128

Merged
merged 4 commits into from
Feb 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/zeroconf/_services/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ def __init__(
self.done = False
self._first_request: bool = True
self._next_send_timer: Optional[asyncio.TimerHandle] = None
self._query_sender_task: Optional[asyncio.Task] = None

if hasattr(handlers, 'add_service'):
listener = cast('ServiceListener', handlers)
Expand All @@ -329,7 +330,7 @@ def _async_start(self) -> None:
self.query_scheduler.start(current_time_millis())
self.zc.async_add_listener(self, [DNSQuestion(type_, _TYPE_PTR, _CLASS_IN) for type_ in self.types])
# Only start queries after the listener is installed
asyncio.ensure_future(self._async_start_query_sender())
self._query_sender_task = asyncio.ensure_future(self._async_start_query_sender())

@property
def service_state_changed(self) -> SignalRegistrationInterface:
Expand Down Expand Up @@ -436,6 +437,8 @@ def _async_cancel(self) -> None:
self.done = True
self._cancel_send_timer()
self.zc.async_remove_listener(self)
assert self._query_sender_task is not None, "Attempted to cancel a browser that was not started"
self._query_sender_task.cancel()

def _generate_ready_queries(self, first_request: bool, now: float) -> List[DNSOutgoing]:
"""Generate the service browser query for any type that is due."""
Expand Down