Skip to content

Feat long live zmq context pool - #1

Closed
OutstanderWang wants to merge 6 commits into
mainfrom
feat_long_live_zmq_context_pool
Closed

Feat long live zmq context pool#1
OutstanderWang wants to merge 6 commits into
mainfrom
feat_long_live_zmq_context_pool

Conversation

@OutstanderWang

Copy link
Copy Markdown
Owner

Feat long live zmq context pool

OutstanderWang and others added 6 commits July 30, 2026 22:11
…call

The with_zmq_socket decorator created a brand-new zmq.asyncio.Context() per
RPC call and context.term()'d it in the finally block. Under the high-concurrency
agent-loop store path this churned libzmq's signaler file descriptors and crashed
the worker (signaler.cpp Bad file descriptor -> SIGABRT), and could also hang on
the blocking term() (aggravated by sock.close(linger=-1)).

Fix: the decorator now reuses the owner's long-lived context via a required
get_context callable, and only creates/closes the DEALER socket per call. The
context is created once per owner and terminated once at close(). Contexts are
thread-safe and event-loop-agnostic, so a single shared context is safe across
loops/threads; each socket stays per-call on one loop.

- zmq_utils.with_zmq_socket: add required get_context; drop per-call
  Context()/term(); change sock.close(linger=-1) -> linger=0.
- client.AsyncTransferQueueClient: own a shared self.zmq_context; destroy(linger=0)
  in close().
- simple_storage_manager: feed the base StorageManager's self.zmq_context via
  get_context.
- base.StorageManager.close(): term() -> destroy(linger=0) so a leaked socket
  cannot hang shutdown.
- tests: add test_zmq_shared_context.py asserting concurrent RPCs reuse one
  context and it is closed exactly once.

Microbenchmark: ~7.6x faster socket setup/teardown (~210us saved per call).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This reverts commit b54c4093d71348b3c82572ff18c3a35a0bb9dd2b.
This reverts commit a8bfbd81c68226f0c679ce3673c467866d470881.
@OutstanderWang
OutstanderWang force-pushed the feat_long_live_zmq_context_pool branch from 9481fdb to 114a259 Compare July 30, 2026 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant