diff --git a/app/services/delivery.py b/app/services/delivery.py index d394ec1..adeb8ec 100644 --- a/app/services/delivery.py +++ b/app/services/delivery.py @@ -509,7 +509,10 @@ async def _run(self) -> None: if timeout is None: await self._wake.wait() else: - await asyncio.wait_for(self._wake.wait(), timeout) + # asyncio.timeout, not wait_for: on Python 3.11 wait_for can swallow a + # cancellation, and stop() would then wait for this loop forever. + async with asyncio.timeout(timeout): + await self._wake.wait() except TimeoutError: timed_out = True self._wake.clear() diff --git a/app/services/ephemeral.py b/app/services/ephemeral.py index 842e3cd..cfa6632 100644 --- a/app/services/ephemeral.py +++ b/app/services/ephemeral.py @@ -249,7 +249,10 @@ def _timeout(self) -> float: async def _run(self) -> None: while True: with contextlib.suppress(TimeoutError): - await asyncio.wait_for(self._wake.wait(), self._timeout()) + # asyncio.timeout, not wait_for: on Python 3.11 wait_for can swallow a + # cancellation, and stop() would then wait for this loop forever. + async with asyncio.timeout(self._timeout()): + await self._wake.wait() self._wake.clear() try: await self.expire_if_due()