Skip to content

Commit 9db988d

Browse files
committed
fix: close ws_client on connect_websocket failure to prevent thread leak
WebSocketClient starts a background thread on creation. If connect() fails (e.g. SFU full), the client was not being closed, leaking the thread.
1 parent 5af1ac6 commit 9db988d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

getstream/video/rtc/connection_utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,8 @@ async def connect_websocket(
431431
"""
432432
logger.info(f"Connecting to WebSocket at {ws_url}")
433433

434+
ws_client = None
435+
success = False
434436
try:
435437
# Create JoinRequest for WebSocket connection
436438
join_request = await create_join_request(token, session_id)
@@ -456,6 +458,7 @@ async def connect_websocket(
456458
sfu_event = await ws_client.connect()
457459

458460
logger.debug("WebSocket connection established")
461+
success = True
459462
return ws_client, sfu_event
460463

461464
except SignalingError as e:
@@ -473,3 +476,6 @@ async def connect_websocket(
473476
except Exception as e:
474477
logger.error(f"Failed to connect WebSocket to {ws_url}: {e}")
475478
raise SignalingError(f"WebSocket connection failed: {e}")
479+
finally:
480+
if ws_client and not success:
481+
ws_client.close()

0 commit comments

Comments
 (0)