fix: catch OSError in websocket send to prevent server crash send_soc…#14474
fix: catch OSError in websocket send to prevent server crash send_soc…#14474Chaudhary-Harshit wants to merge 1 commit into
Conversation
…ket_catch_exception only caught ConnectionError and its subclasses (ConnectionResetError, BrokenPipeError). When a client becomes unreachable mid-generation (laptop sleeps, drops off WiFi), the OS raises OSError: [Errno 113] No route to host (EHOSTUNREACH), which is a sibling of ConnectionError, not a subclass. It therefore escaped the handler, propagated through publish_loop, and could crash the entire server over a single dead client.
|
@comfyanonymous Please review the PR |
📝 WalkthroughWalkthrough
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests-unit/server_test/test_send_socket_catch_exception.py (1)
30-38: 💤 Low valueConsider verifying the "nothing is logged" claim in the docstring.
The docstring states that nothing is logged when the send succeeds, but this assertion is not included in the test. While the test correctly verifies the message is delivered, adding a caplog check would ensure the documented behavior is validated.
📝 Suggested enhancement
- async def test_successful_send_delivers_message(self): + async def test_successful_send_delivers_message(self, caplog): """When the send succeeds the message is passed through and nothing is logged.""" received = [] async def ok_send(message): received.append(message) await send_socket_catch_exception(ok_send, b"hello") assert received == [b"hello"] + assert "send error" not in caplog.text🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests-unit/server_test/test_send_socket_catch_exception.py` around lines 30 - 38, The test method test_successful_send_delivers_message has a docstring claiming that nothing is logged when the send succeeds, but the test only verifies the message delivery without actually asserting that no logs were captured. Add a caplog fixture parameter to the test method and include an assertion to verify that the caplog is empty or contains no log records, thus validating the documented behavior that nothing should be logged during successful message delivery.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests-unit/server_test/test_send_socket_catch_exception.py`:
- Around line 30-38: The test method test_successful_send_delivers_message has a
docstring claiming that nothing is logged when the send succeeds, but the test
only verifies the message delivery without actually asserting that no logs were
captured. Add a caplog fixture parameter to the test method and include an
assertion to verify that the caplog is empty or contains no log records, thus
validating the documented behavior that nothing should be logged during
successful message delivery.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: a7b0397b-43d9-4271-800e-1b587682bc74
📒 Files selected for processing (2)
server.pytests-unit/server_test/test_send_socket_catch_exception.py
fix: catch OSError in websocket send to prevent server crash
Summary
Fixes #1442. A websocket client that becomes unreachable mid-generation
could crash the entire ComfyUI server with an uncaught
OSError.When it happens
While a generation is running, the server pushes progress updates to
connected clients over the websocket. If a client disappears abruptly —
laptop sleeps, drops off WiFi/VPN, remote route breaks — the OS raises
OSError: [Errno 113] No route to host(EHOSTUNREACH) on the next send.Root cause
send_socket_catch_exception(server.py) only caughtConnectionErrorand its subclasses: