Skip to content

Commit 2233b6b

Browse files
authored
fix: race with InvalidStateError when async_request times out (#1208)
1 parent 063b5d9 commit 2233b6b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/zeroconf/_services/info.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ def instance_name_from_service_info(info: "ServiceInfo") -> str:
8989
_cached_ip_addresses = lru_cache(maxsize=256)(ip_address)
9090

9191

92+
def _set_future_none_if_not_done(fut: asyncio.Future) -> None:
93+
"""Set a future to None if it is not done."""
94+
if not fut.done(): # pragma: no branch
95+
fut.set_result(None)
96+
97+
9298
class ServiceInfo(RecordUpdateListener):
9399
"""Service information.
94100
@@ -235,7 +241,7 @@ async def async_wait(self, timeout: float) -> None:
235241
loop = asyncio.get_running_loop()
236242
future = loop.create_future()
237243
self._new_records_futures.append(future)
238-
handle = loop.call_later(millis_to_seconds(timeout), future.set_result, None)
244+
handle = loop.call_later(millis_to_seconds(timeout), _set_future_none_if_not_done, future)
239245
try:
240246
await future
241247
finally:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy