fix: prevent silent message loss on zmq socket#951
Merged
Conversation
ZMQ ROUTER sockets without ROUTER_MANDATORY silently drop messages when the per-peer send pipe is full — send_multipart() returns success but the message is discarded by libzmq. With ROUTER_MANDATORY=1, a full pipe raises EAGAIN, which pyzmq's async layer handles via backpressure (queues the send and retries when the client drains). Also unbounds the response path (server SNDHWM=0, client RCVHWM=0) so completed responses are never dropped — the work is already done, losing the result is pure waste. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
willccbb
approved these changes
Feb 22, 2026
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.
Summary
ZMQ_ROUTER_MANDATORY=1on the server's ROUTER socket so full send pipes raise EAGAIN for automatic retries instead of silently dropping messagesSNDHWM=0,RCVHWM=0on both sides), concurrency limits are set by application (e.g. how many concurrent)The bug
ZMQ ROUTER sockets silently drop messages when the per-peer send pipe is full.
send_multipart()returns success, but the message is discarded by libzmq. The server logs no error. The client waits for a response that will never arrive (up to the 10h default timeout).This happens under high concurrency when responses accumulate faster than the client can drain them — event loop lag, GC pauses, or large response payloads can all trigger it well below the nominal HWM message count. The buffer doesn't need to hit 10,000 messages; it just needs to fill faster than the client's event loop can call
recv.How
ROUTER_MANDATORYfixes itWithout it:
With it, two cases:
Minimal repro
Without fix:
With
USE_ROUTER_MANDATORY = True:Eval Repro
Set socket message buffer limits much lower (e.g. to reach capacity faster) and then run
This will never finish as some messages are lost. From this branch, it works tho
Test plan
HWM=10🤖 Generated with Claude Code
Note
Medium Risk
Changes core IPC behavior (buffering/backpressure and error handling) which can affect throughput and memory under load, but is localized to ZMQ client/server socket configuration and send path.
Overview
Prevents silent response loss in the ZMQ env transport under high concurrency by enabling
ROUTER_MANDATORYon the server and settingSNDHWM/RCVHWMto unlimited (0) on both client and server.Server response sending is now wrapped in a
try/exceptto log and ignorezmq.ZMQError(e.g., disconnected clients) instead of failing silently/crashing. Also tightens typing inEnvironmentbycasting callabledataset/eval_datasetinputs toDatasetBuilder.Written by Cursor Bugbot for commit 9cd0052. This will update automatically on new commits. Configure here.