From e868b67ae06430ebe7605a5348f038df21f25bf2 Mon Sep 17 00:00:00 2001 From: lhchavez Date: Thu, 18 Jul 2024 14:47:53 +0000 Subject: [PATCH] Also close the WebSocket when we close the session When we're closing sessions, we do not close the WebSocket and instead kinda rely on the server kicking us out due to inactivity. This makes it racy for cases like connection retries (which we have disabled and instead close any previous sessions), where we can have two concurrent connections for the same session id. An invariant violation! This change now also makes sure to close the WebSocket when the session is closed. --- pyproject.toml | 2 +- replit_river/session.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 9cac48c..d630690 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name="replit-river" -version="0.2.19" +version="0.2.20" description="Replit river toolkit for Python" authors = ["Replit "] license = "LICENSE" diff --git a/replit_river/session.py b/replit_river/session.py index 98b4857..c1c4b06 100644 --- a/replit_river/session.py +++ b/replit_river/session.py @@ -536,4 +536,5 @@ async def close(self) -> None: stream.close() async with self._stream_lock: self._streams.clear() + await self.close_websocket(self._ws_wrapper, should_retry=False) self._state = SessionState.CLOSED