Skip to content

fix(zero-cache): don't crash when a handed-off socket closed on the way - #129

Merged
tmm merged 1 commit into
mainfrom
zero-cache-handoff-closed-socket
Nov 10, 2026
Merged

tmm merged 1 commit into
mainfrom
zero-cache-handoff-closed-socket

Conversation

@tmm

@tmm tmm commented Nov 10, 2026

Copy link
Copy Markdown
Member

main's Swift end-to-end (macOS) job failed at a0df53f (run 42909644773). 14 HardenE2ETests timed out, and ChaosFuzz seed 1 stopped converging. The cause is in zero-cache, not the Swift client. The job's server.log artifact shows the dispatcher dying right after the chaos fuzz cut two clients:

21:59:48.932 pid=6373,worker=dispatcher uncaughtException {"name":"TypeError","errorMsg":"Cannot read properties of undefined (reading 'on')",
  "stack":"… websocket-handoff.ts:80:12 … websocket-handoff.ts:162:7 … processes.ts:96:7 …"}
…
zero-cache exited with 13

When a connection closes while the runner sends it to the dispatcher, Node delivers the handoff message with no socket. The Node docs say message handlers in the subprocess "should verify that socket exists". Since #112, the dispatcher calls socket.on('error', …) as soon as the message arrives, so a missing socket throws, the exception goes uncaught, and the process exits. Before #112 the dispatcher only forwarded the socket, and the syncer's installWebSocketReceiver already checks if (!socket).

With this change, the dispatcher drops such a message and logs websocket closed during handoff, as the syncer does.

The new test in websocket-handoff.test.ts delivers a handoff without a socket. On main it fails with the same TypeError; with this change it passes. tsc and oxfmt are clean.

No changeset: zero-cache isn't versioned here.

When a connection closes while the runner sends it to the dispatcher, Node
delivers the handoff message without the socket. Since #112 the dispatcher
calls socket.on('error', …) as soon as the message arrives, so a missing
socket threw a TypeError, an uncaught exception that exits zero-cache with
code 13. main's Swift end-to-end job hit it at a0df53f: the dispatcher died
at websocket-handoff.ts:80 right after the chaos fuzz cut two clients, and
every later end-to-end test timed out.

The dispatcher now drops such a message, as installWebSocketReceiver already
does in the syncer.

Amp-Thread-ID: https://ampcode.com/threads/T-0d2ed206-a5dd-4f42-9b68-c56e6b23e8f6
Co-authored-by: tmm <tmm@tmm.dev>
@tmm
tmm merged commit 33712ed into main Nov 10, 2026
10 checks passed
@tmm
tmm deleted the zero-cache-handoff-closed-socket branch November 10, 2026 22:47
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.

2 participants