From 957a3ea26131f9f810f652097449de4e7ef0f478 Mon Sep 17 00:00:00 2001 From: Bruce Merry Date: Fri, 6 Dec 2024 10:02:30 +0200 Subject: [PATCH] Fix infinite callback loop when used with async-solipsism If the keepalive handler is called too soon, it reschedules itself. The test used `now <= close_time`, which means that an exactly on-time notification is treated as "too soon", causing an automatic rescheduling. For real systems the time will eventually advance and break the loop, but with async-solipsism, time doesn't advance until there is some reason to sleep and the loop is infinite. Closes #10149. --- aiohttp/web_protocol.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiohttp/web_protocol.py b/aiohttp/web_protocol.py index 0bffc849817..3d76fc1f1d7 100644 --- a/aiohttp/web_protocol.py +++ b/aiohttp/web_protocol.py @@ -487,7 +487,7 @@ def _process_keepalive(self) -> None: loop = self._loop now = loop.time() close_time = self._next_keepalive_close_time - if now <= close_time: + if now < close_time: # Keep alive close check fired too early, reschedule self._keepalive_handle = loop.call_at(close_time, self._process_keepalive) return