Repository navigation
Fix websocket infinite loop on user disconnect - #439
Merged
Merged
Conversation
- Add break statement in WebSocketDisconnect handler to exit loop properly - Prevent double unsubscription with unsubscribed flag tracking - Improve exception handling for critical errors (RuntimeError, ConnectionError) - Add comprehensive test suite covering disconnect scenarios - Ensure proper cleanup in finally block Fixes infinite loop issue that occurred when users disconnected from websocket Co-authored-by: openhands <openhands@all-hands.dev>
tofarr
marked this pull request as ready for review
September 23, 2025 14:13
xingyaoww
approved these changes
Sep 23, 2025
Contributor
|
Agent Server image for this PR Pull (multi-arch manifest): docker pull ghcr.io/all-hands-ai/agent-server:a00799aRun: docker run -it --rm \
-p 8000:8000 \
--name agent-server-a00799a \
ghcr.io/all-hands-ai/agent-server:a00799aThis tag is a multi-arch manifest (amd64/arm64). Your client pulls the right arch automatically. |
StressTestor
pushed a commit
to StressTestor/software-agent-sdk
that referenced
this pull request
Jun 1, 2026
Co-authored-by: openhands <openhands@all-hands.dev>
1 of 7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The websocket code in
event_router.pyhad several issues that caused infinite loops when users disconnected:WebSocketDisconnectexception handler was missing abreakstatement, causing the loop to continue indefinitely after a disconnectSolution
Core Fixes
WebSocketDisconnectexception handler to properly exit the loop when a user disconnectsunsubscribedflag to track subscription stateRuntimeError,ConnectionError) that indicate the websocket is brokenTesting
Changes Made
Modified Files
openhands/agent_server/event_router.py: Fixed the websocket loop logictests/agent_server/test_event_router_websocket.py: Added comprehensive test suiteKey Changes
breakstatement inWebSocketDisconnecthandlerunsubscribedflag to prevent double unsubscriptionTesting
Impact
This fix resolves the infinite loop issue that occurred when users disconnected from websocket connections, ensuring proper cleanup and resource management.
@tofarr can click here to continue refining the PR