Skip to content

fix(messaging): stream the Linux listener table so a busy host is not refused - #8855

Merged
lidge-jun merged 1 commit into
devfrom
goat/remote-messaging-receipt-flake
Nov 16, 2026
Merged

lidge-jun merged 1 commit into
devfrom
goat/remote-messaging-receipt-flake

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

On Linux, remotePortIsLoopback (src/messaging/remote-ports.ts) read /proc/net/tcp into a fixed 4 MiB buffer and returned false when the table was larger. The table lists every TCP socket on the host, including TIME_WAIT, so on a machine with about 28,000 sockets every return lease was refused. The owner then closed the control connection, and the caller got remote_control_unknown ("Messaging control outcome is unconfirmed") from the abort path in remoteControl (src/messaging/remote-auth.ts:68). This is a product defect: a busy dev box or shared runner could not hold any remote messaging route.

Both tables are now streamed row by row in 64 KiB chunks, with no size limit and bounded memory. The fail-closed rules are unchanged: a public listener anywhere in either table still refuses the port, read and permission errors still throw, and only a missing IPv6 table counts as empty. structure/remote-messaging.md records this.

Context: the lane=all run 43928410201, job test 5/5 (job 133514225378, runner lidge-ocx-02), failed messaging-remote-send.test.ts > "remote malformed preserves precise receipt and never replays" with this error. Because sendRemoteMessage turns every error into a receipt, the thrown error must come from the message/lease calls in the pair.owners() fixture, before any send.

How sure I am that this was the trigger for that particular run: not proven. In a Linux container (oven/bun:1.4.4), this cap reproduces the exact error and stack every time. But that failing test took 8.25 ms, and its passing siblings did two full table scans in about 16 ms, which suggests the runner's table was small at the time. Another quick false is also possible: an unrelated listener on a non-loopback address that shares the fixture's port number. The fixture reserves ports that are free only on 127.0.0.1. I could not inspect the runner's listeners, so that path is unconfirmed and this PR does not change it. #8850 (budget stage timers, rpc.ts) plays no part: nothing on this path waits near a deadline in 8 ms. For the same reason, the authenticatedRemoteSocket timer at remote-auth.ts:28 is not the cause and is left as is.

Verification

All test runs used /usr/bin/lockf -k /tmp/ocx-test.lock, single files only.

  • Red: the new case in tests/codex-integration/messaging-remote-process.test.ts fails on origin/dev (2589be5) with "Expected: true, Received: false".
  • Green: the same file passes with the fix, 16 pass / 0 fail. The new case puts a loopback listener in a table over 4 MiB and expects true. It also puts a public listener past the old 4 MiB cut-off and expects false, which proves the whole table is still read.
  • End-to-end in a Linux container with about 31,000 sockets (/proc/net/tcp about 4.6 MB):
    • Before: messaging-remote-send.test.ts failed with remote_control_unknown in 17/17, 17/17 and 16/17 cases. Instrumentation confirmed the size cap and the lease refusal at remote-owner.ts:65.
    • After: remotePortIsLoopback returned false 0 of 20 times, and remote_control_unknown no longer appeared. The remaining failures in that stress run were EADDRINUSE, a separate mode noted below.
  • Neighbours on macOS, all passing: messaging-remote-send (17), messaging-remote-port-reservation (13), messaging-remote-admission (11), messaging-remote-lifecycle (12), messaging-remote-gaps (6).
  • bun run typecheck, bun run structure:check and bun run privacy:scan all pass.

NOT RUN: the full bun run test suite (this host is shared; the brief asked for single files only, and CI is labeled ci:full); a live inspection of lidge-ocx-02's listener table; macOS/Windows lanes.

Known and left out of this PR:

  • When 32k connections churn on the same host, the fixture's reserve-then-release ports can be taken before Bun.serve binds them (EADDRINUSE). That has not been seen on CI.
  • src/server/port-reclaim.ts has a similar MAX_PROC_NET_BYTES refusal for Remote Link owner lookups. That is a separate subsystem and deserves its own change.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Summary by CodeRabbit

  • Bug Fixes
    • Improved Linux remote-connection checks on systems with large network tables. Checks now account for the full set of listener information, reducing the chance that a public-facing listener is missed and ensuring loopback-only connections are assessed consistently. This helps prevent connections from being accepted when an exposed listener is present, even if it appears later in the system’s network information.

… refused

remotePortIsLoopback read /proc/net/tcp into a fixed 4 MiB buffer and
returned false when the table was larger. The table lists every TCP
socket on the host, including TIME_WAIT, so a machine with about 28,000
sockets refused every return lease. The owner then closed the control
connection and the caller saw remote_control_unknown.

Stream both tables row by row with bounded memory and no size limit. A
public listener anywhere in either table still refuses the port.

Seen in the lane=all run 43928410201 "test 5/5" failure in
messaging-remote-send.test.ts.
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner November 16, 2026 19:10
@lidge-jun lidge-jun added the ci:full Run the four full Ubuntu test shards on this pull request label Nov 16, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T19:12:08.885773Z abbbc0c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Nov 16, 2026
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Linux listener inspection now streams /proc/net/tcp and /proc/net/tcp6 rows instead of reading each table into a fixed-size buffer. It accepts a port only when a loopback listener exists and no exposed listener exists. An integration test covers tables larger than 4 MiB.

Changes: Linux listener inspection

Layer / File(s) Summary
Stream and classify listener rows
src/messaging/remote-ports.ts, tests/codex-integration/messaging-remote-process.test.ts, structure/remote-messaging.md
The inspection reads tables in chunks and tracks matching loopback and exposed listeners. It returns false if an unterminated row exceeds 4096 bytes. The integration test covers a table larger than 4 MiB, and the documentation describes the inspection.

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

Change: Bug fix

Suggested labels: bug

Suggested reviewers: phillipod

Merge Risk: Minimal · up to abbbc

Linux listener inspection now handles very large socket tables without the size limit, and public listeners are still refused. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: Linux listener-table inspection now streams the table so a busy host is not refused. The raw summary and objectives both confirm the change replaces the fixed 4 MiB bu…
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.
Full details: Title check

Explanation

The title names the main change: Linux listener-table inspection now streams the table so a busy host is not refused. The raw summary and objectives both confirm the change replaces the fixed 4 MiB buffer with streaming for /proc/net/tcp and /proc/net/tcp6. The title is specific, uses the fix(messaging) convention, and stays within the 13-word, single-sentence guidance. It is slightly long but remains clear.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 2589be5 and abbbc0c.

Files selected for processing: 3

  • src/messaging/remote-ports.ts
  • structure/remote-messaging.md
  • tests/codex-integration/messaging-remote-process.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@lidge-jun
lidge-jun merged commit 643ca8f into dev Nov 16, 2026
39 of 41 checks passed
@lidge-jun
lidge-jun deleted the goat/remote-messaging-receipt-flake branch November 16, 2026 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ci:full Run the four full Ubuntu test shards on this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant