Skip to content

fix(runtime): remove ZMQ publisher port allocation race - #14566

Merged
jthomson04 merged 2 commits into
mainfrom
jthomson04/fix-zmq-publisher-bind-race
Sep 10, 2026
Merged

jthomson04 merged 2 commits into
mainfrom
jthomson04/fix-zmq-publisher-bind-race

Conversation

@jthomson04

@jthomson04 jthomson04 commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Remove a race during concurrent ZMQ publisher startup. The existing code selects a free port with a temporary TCP listener, closes it, then binds the publisher to that port. Another socket can take the port between those steps.

Details

  • Translate TCP :0 endpoints to :*, preserving the host, and bind the actual ZMQ socket once.
  • Read the assigned address from that socket through get_last_endpoint() for logging and discovery.
  • Propagate endpoint lookup and decoding errors without panics.
  • Remove the unused temporary-listener error helper and its test.

No new locks, dependencies, wire changes, or per-request work. Publisher retries and readiness are unchanged.

Where should the reviewer start?

lib/runtime/src/transports/event_plane/zmq_transport.rs, starting with ZmqPubTransport::bind.

Validation

  • cargo test -p dynamo-runtime --lib transports::event_plane — 44 passed, covering PUB/SUB delivery through the assigned endpoint.
  • cargo check -p dynamo-runtime --locked
  • cargo clippy -p dynamo-runtime --lib --tests --locked -- -D warnings
  • cargo fmt --all --check
  • git diff --check

No cluster runs or active benchmark changes.

Related Issues

  • Confirmed — no related issue

Summary by CodeRabbit

  • Bug Fixes
    • Improved ephemeral network port allocation for ZMQ connections.
    • Prevented port conflicts during concurrent connections.
    • Updated publish/subscribe connectivity checks to use dynamically assigned ports.

@jthomson04
jthomson04 requested a review from a team as a code owner September 9, 2026 23:46
@github-actions github-actions Bot added the fix label Sep 9, 2026
@coderabbitai

coderabbitai Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 442a4f3a-c768-46df-8db1-36b1fa4d4408

📥 Commits

Reviewing files that changed from the base of the PR and between 7540ca8 and 82926d8.

📒 Files selected for processing (1)
  • lib/runtime/src/transports/event_plane/zmq_transport.rs

Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review.


Walkthrough

ZMQ publisher binding now uses libzmq to allocate ephemeral TCP ports and returns the actual endpoint. The temporary listener and standalone I/O error test were removed. Tests cover concurrent unique ports and ephemeral PUB/SUB communication.

Changes

ZMQ ephemeral binding

Layer / File(s) Summary
Direct ephemeral publisher binding
lib/runtime/src/transports/event_plane/zmq_transport.rs
ZmqPubTransport::bind binds wildcard TCP endpoints through libzmq and reads the assigned endpoint with get_last_endpoint. Socket errors use the unified TMQ mapping.
Ephemeral binding validation
lib/runtime/src/transports/event_plane/zmq_transport.rs
Tests verify 32 concurrent publishers receive unique live ports. The PUB/SUB test uses an ephemeral endpoint, and the obsolete I/O error test was removed.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 82926

Publishers now obtain ephemeral TCP ports atomically through ZMQ and report the assigned endpoint, eliminating the temporary-port reservation race. The covered binding and communication behavior indicates no remaining merge-blocking risk.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: removing the ZMQ publisher port allocation race.
Description check ✅ Passed The description covers the change, implementation details, reviewer starting point, validation, and the required Related Issues section. The Summary heading differs from the template's Overview headin…
  • Fix all pre-merge checks with AI

Comment @coderabbitai help to get the list of available commands.

@copy-pr-bot

copy-pr-bot Bot commented Sep 10, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@jthomson04

Copy link
Copy Markdown
Contributor Author

/ok to test 84407f7

@jthomson04
jthomson04 enabled auto-merge (squash) September 10, 2026 00:25
jthomson04 and others added 2 commits September 9, 2026 19:11
Bind ephemeral ports on the actual ZMQ publisher socket and read back its endpoint. Avoid releasing a temporary TCP port before the publisher binds. Preserve the requested TCP host and existing socket settings.

Base: 7540ca8

Validation: 45 focused event-plane tests; cargo check -p dynamo-runtime --locked; cargo clippy -p dynamo-runtime --lib --tests --locked -- -D warnings; cargo fmt --all --check; git diff --check.
Signed-off-by: jthomson04 <[email protected]>
The test did not exercise the bind race it was named for. The
duplicate-port assertion cannot fail under the old implementation
either, since the OS never hands two live listeners the same ephemeral
port, and the race itself surfaced as a bind error that the test only
caught incidentally and only within a narrow window.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
@jthomson04
jthomson04 force-pushed the jthomson04/fix-zmq-publisher-bind-race branch from 84407f7 to 449a695 Compare September 10, 2026 02:11
@jthomson04

Copy link
Copy Markdown
Contributor Author

/ok to test 449a695

@jthomson04
jthomson04 merged commit 650b227 into main Sep 10, 2026
121 checks passed
@jthomson04
jthomson04 deleted the jthomson04/fix-zmq-publisher-bind-race branch September 10, 2026 03:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants