Skip to content

Commit

Permalink
Don't bother with fire-and-forget WS closure
Browse files Browse the repository at this point in the history
This introduces more problems than what it solves, since now if the
application wants to exit, it may orphan this and cause a lot of
logspam.

This change now closes the websocket synchronously to avoid leaking
tasks upon exit.
  • Loading branch information
lhchavez committed Aug 14, 2024
1 parent b4f084d commit 402134e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions replit_river/websocket_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ async def close(self) -> None:
async with self.ws_lock:
if self.ws_state == WsState.OPEN:
self.ws_state = WsState.CLOSING
task = asyncio.create_task(self.ws.close())
task.add_done_callback(
lambda _: logger.debug("old websocket %s closed.", self.ws.id)
)
try:
await self.ws.close()
finally:
logger.debug("old websocket %s closed.", self.ws.id)
self.ws_state = WsState.CLOSED

0 comments on commit 402134e

Please sign in to comment.