Repository navigation
fix(messaging): stream the Linux listener table so a busy host is not refused - #8855
Conversation
… 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.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
✅ Deterministic PR hygiene checks passed. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Summary
On Linux,
remotePortIsLoopback(src/messaging/remote-ports.ts) read/proc/net/tcpinto a fixed 4 MiB buffer and returnedfalsewhen 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 gotremote_control_unknown("Messaging control outcome is unconfirmed") from the abort path inremoteControl(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.mdrecords this.Context: the lane=all run 43928410201, job
test 5/5(job 133514225378, runnerlidge-ocx-02), failedmessaging-remote-send.test.ts> "remote malformed preserves precise receipt and never replays" with this error. BecausesendRemoteMessageturns every error into a receipt, the thrown error must come from themessage/leasecalls in thepair.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 quickfalseis 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, theauthenticatedRemoteSockettimer atremote-auth.ts:28is not the cause and is left as is.Verification
All test runs used
/usr/bin/lockf -k /tmp/ocx-test.lock, single files only.tests/codex-integration/messaging-remote-process.test.tsfails onorigin/dev(2589be5) with "Expected: true, Received: false".true. It also puts a public listener past the old 4 MiB cut-off and expectsfalse, which proves the whole table is still read./proc/net/tcpabout 4.6 MB):messaging-remote-send.test.tsfailed withremote_control_unknownin 17/17, 17/17 and 16/17 cases. Instrumentation confirmed the size cap and the lease refusal atremote-owner.ts:65.remotePortIsLoopbackreturnedfalse0 of 20 times, andremote_control_unknownno longer appeared. The remaining failures in that stress run wereEADDRINUSE, a separate mode noted below.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:checkandbun run privacy:scanall pass.NOT RUN: the full
bun run testsuite (this host is shared; the brief asked for single files only, and CI is labeledci:full); a live inspection oflidge-ocx-02's listener table; macOS/Windows lanes.Known and left out of this PR:
Bun.servebinds them (EADDRINUSE). That has not been seen on CI.src/server/port-reclaim.tshas a similarMAX_PROC_NET_BYTESrefusal for Remote Link owner lookups. That is a separate subsystem and deserves its own change.Checklist
Summary by CodeRabbit