Skip to content

Commit c2a69dd

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/main'
2 parents d42df5a + 7436fcf commit c2a69dd

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

rlm/core/lm_handler.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def handle(self):
2222
request_data = socket_recv(self.connection)
2323
if not isinstance(request_data, dict):
2424
response = LMResponse.error_response("Request must be a JSON object")
25-
socket_send(self.connection, response.to_dict())
25+
self._safe_send(response)
2626
return
2727

2828
request = LMRequest.from_dict(request_data)
@@ -37,11 +37,26 @@ def handle(self):
3737
else:
3838
response = LMResponse.error_response("Missing 'prompt' or 'prompts' in request.")
3939

40-
socket_send(self.connection, response.to_dict())
40+
self._safe_send(response)
41+
42+
except (BrokenPipeError, ConnectionError, ConnectionResetError, OSError):
43+
# Client disconnected - this is expected during parallel execution
44+
# when workers complete and close their sockets. Silently ignore.
45+
pass
4146

4247
except Exception as e:
48+
# Try to send error response, but don't fail if socket is broken
4349
response = LMResponse.error_response(str(e))
50+
self._safe_send(response)
51+
52+
def _safe_send(self, response: LMResponse) -> bool:
53+
"""Send response, returning False if the socket is broken."""
54+
try:
4455
socket_send(self.connection, response.to_dict())
56+
return True
57+
except (BrokenPipeError, ConnectionError, ConnectionResetError, OSError):
58+
# Client disconnected - silently ignore
59+
return False
4560

4661
def _handle_single(self, request: LMRequest, handler: "LMHandler") -> LMResponse:
4762
"""Handle a single prompt request."""

0 commit comments

Comments
 (0)