Skip to content

Commit

Permalink
Prevent reconnects
Browse files Browse the repository at this point in the history
We have some problems with reconnects, and it's probably better to
completely disable transparent reconnects until we have that sorted out.

This change now proactively closes and deletes any outstanding sessions
when we detect that the WebSocket transport was closed.
  • Loading branch information
lhchavez committed Jul 17, 2024
1 parent bd814c2 commit 8a02d5a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name="replit-river"
version="0.2.18"
version="0.2.19"
description="Replit river toolkit for Python"
authors = ["Replit <eng@replit.com>"]
license = "LICENSE"
Expand Down
16 changes: 15 additions & 1 deletion replit_river/client_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,27 @@ async def _create_new_session(
is_server=False,
handlers={},
close_session_callback=self._delete_session,
retry_connection_callback=lambda _: self._get_or_create_session(),
retry_connection_callback=lambda _: self._retry_connection(),
)

self._set_session(new_session)
await new_session.start_serve_responses()
return new_session

async def _retry_connection(self) -> ClientSession:
"""Deletes any outstanding sessions and creates a new one."""
async with self._session_lock:
sessions = self._sessions.values()
logging.info(
f"start closing transport {self._transport_id}, number sessions : "
f"{len(sessions)}"
)
sessions_to_close = list(sessions)
self._sessions.clear()
tasks = [session.close() for session in sessions_to_close]
await asyncio.gather(*tasks)
return await self._get_or_create_session()

async def _get_or_create_session(self) -> ClientSession:
async with self._create_session_lock:
existing_session = await self._get_existing_session()
Expand Down

0 comments on commit 8a02d5a

Please sign in to comment.