Skip to content

Commit 2425489

Browse files
committed
Ensure reconnection backoff is reset between sessions
Adjusted Log level for sse reconnection to match the actual importance of the event.
1 parent f14eea9 commit 2425489

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

pyhilo/graphql.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ async def _drain_sse_events(
677677
except StopAsyncIteration:
678678
break
679679
except asyncio.TimeoutError:
680-
LOG.warning(
680+
LOG.info(
681681
"SSE keepalive timeout (%ss without data), reconnecting...",
682682
self._SSE_KEEPALIVE_TIMEOUT,
683683
)
@@ -743,6 +743,28 @@ async def _listen_to_sse(
743743
)
744744
await asyncio.sleep(5)
745745

746+
except asyncio.TimeoutError:
747+
# Keepalive timeout: the connection was recently live, so start
748+
# the next reconnect cycle with the base delay (not accumulated).
749+
backoff_delay = self._BACKOFF_BASE
750+
LOG.debug(
751+
"Reconnecting after keepalive timeout in %s seconds...",
752+
backoff_delay,
753+
)
754+
await asyncio.sleep(backoff_delay)
755+
backoff_delay = min(backoff_delay * 2, self._BACKOFF_MAX)
756+
if "query" in payload:
757+
del payload["query"]
758+
if location_hilo_id:
759+
try:
760+
await self.call_get_location_query(location_hilo_id)
761+
LOG.debug("call_get_location_query success after reconnect")
762+
except Exception as e2:
763+
LOG.error(
764+
"exception while RE-connecting, retrying: %s",
765+
e2,
766+
)
767+
746768
except Exception as e:
747769
LOG.debug(
748770
"Subscription connection lost: %s. Reconnecting in %s seconds...",

0 commit comments

Comments
 (0)