Repository navigation
fix(relay): treat EPIPE/ECONNRESET write failures as the client leaving - #24209
Conversation
|
|
|
||
| // Why: on Windows named pipes a relay write can fail with EPIPE/ECONNRESET before EOF is read. The | ||
| // writer then closed the client as 'local', holding its PTY owner for the full grace. | ||
| describe.skipIf(process.platform === 'win32')('reconnect listener peer write error', () => { |
There was a problem hiding this comment.
Windows write path remains untested
This integration suite skips Windows, although Windows named-pipe write failures are the case this change aims to fix. The classifier unit tests cannot check how a named-pipe write callback and socket close are ordered, so a regression on the target platform could pass. A Windows named-pipe integration case would close that coverage gap.
Knowledge Base Used: Relay protocol and transport
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Important
On Windows a named-pipe write that libuv accepts and that fails at IOCP completion reaches the callback as err.code === 'EOF' (ERROR_BROKEN_PIPE → UV_EOF), which this classifier does not treat as peer departure. The client then still closes as 'local' in the very interleaving this PR targets. Evidence and a suggested direction are in the inline comment.
Reviewed changes
relay-socket-peer-close.ts(new):isRelaySocketPeerClosedreports peer departure only forEPIPE/ECONNRESETon the write error orsocket.errored, deliberately excluding teardown the relay causes (ECANCELED,ECONNABORTED, a bareERR_STREAM_DESTROYED).relay-reconnect-listener.ts: a peer-caused write failure now detaches the socket client aspeer-closedbefore the write settles, so the 250ms grace floor applies instead of the 30s hold.- Tests: new classifier unit tests, a real-dispatcher write-error test over a Unix socket (EPIPE, reset-before-close, own-destroy stays local), and the peer-end test rebuilt on a real dispatcher rather than a cast stub.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| // ERROR_BAD_PIPE) into EPIPE and ERROR_NETNAME_DELETED/WSAECONNRESET into ECONNRESET, and both | ||
| // mean the other end went away. ECANCELED and ECONNABORTED can come from our own close, so a | ||
| // teardown we started would clamp a live owner's grace (see pty-consumer-owner-admission.ts). | ||
| const PEER_CLOSED_SOCKET_ERROR_CODES: ReadonlySet<string> = new Set(['EPIPE', 'ECONNRESET']) |
There was a problem hiding this comment.
On Windows, a named-pipe write that libuv accepts and that later fails at IOCP completion reaches the write callback as err.code === 'EOF' (ERROR_BROKEN_PIPE → UV_EOF); the analogous ERROR_NO_DATA completion is 'EAGAIN'. Neither is in this set, so the detach-first path is skipped and the client still closes as 'local' in exactly the interleaving this PR targets — and the tests, which all skip win32, cannot see it.
Technical details
# Windows async pipe-write completions are not EPIPE
## Affected sites
- `src/relay/relay-socket-peer-close.ts:7` — the accepted set omits `EOF`/`EAGAIN`
- `src/relay/relay-reconnect-listener.ts:103-108` — the write callback skips `detachSocketClient` for those codes, so `onSettled({ok:false})` closes the client as `local`
## Evidence (verified against libuv v1.x and Node 24's bundled libuv 1.52.1)
- Sync `uv_write` path (`src/win/stream.c` uses `uv_translate_write_sys_error`): `ERROR_BROKEN_PIPE`/`ERROR_NO_DATA` → `UV_EPIPE`. This is the case the comment describes, and it is why the manual test likely passed.
- Async IOCP completion (`src/win/pipe.c`, `uv__process_pipe_write_req`) uses `uv_translate_sys_error(GET_REQ_ERROR(req))`, and `GET_REQ_ERROR` = `pRtlNtStatusToDosError(status)`. `STATUS_PIPE_BROKEN` → `ERROR_BROKEN_PIPE` (109) → `UV_EOF`; a status converted to `ERROR_NO_DATA` → `UV_EAGAIN`.
- `uv_err_name(UV_EOF)` is `"EOF"`, so Node's write callback receives `err.code === 'EOF'`. libuv maintainers note both outcomes are nondeterministic (libuv#4548).
## Required outcome
- A queued-then-failed Windows pipe write must still be classified as peer departure, so `detachClient(..., 'peer-closed')` runs before the writer's `'local'` close.
## Suggested approach
- Add `'EOF'` (unambiguous here: a write-completion EOF means the pipe broke). `'EAGAIN'` is the mis-mapped `ERROR_NO_DATA` completion but also signals would-block, so treat it separately; `socket.readableEnded` is another peer-departure signal to consider.
- Note the two peer tests are `describe.skipIf(... === 'win32')`, so this path is never exercised on the platform it targets.
## Open questions for the human
- Was the Windows manual test on a connection with a pending write (backpressure), or only the synchronous hard-fail path?859eb85 to
c2ecb2c
Compare
5063e96 to
3ff605b
Compare
|
Pullfrog couldn't load your Pullfrog secrets on this run. The key is still stored — the runner just couldn't fetch it, so this is a transient failure on our side, not a missing key. To fix: re-run the job. If it keeps happening, tell us in Discord. Model settings → · Setup docs → · Ask in Discord → |
…with EPIPE or ECONNRESET On the Windows arm64 lane a relay write to a named-pipe client could fail with EPIPE or ECONNRESET before EOF arrived. The dispatcher's writer then closed the client as 'local', so its PTY owner kept the full 30s grace instead of the 250ms peer-closed floor and a quick reconnect was refused. The reconnect listener now detaches the client as peer-closed before settling a write that failed with EPIPE/ECONNRESET, or a write attempted after a peer reset destroyed the socket (so ERR_STREAM_DESTROYED counts only via socket.errored). ECANCELED, ECONNABORTED and a plain destroy() stay 'local', since our own teardown can raise them.
3ff605b to
234cc8c
Compare

ELI5
When an SSH client's connection breaks, the relay should treat it as the client leaving, so the client can quickly reclaim its terminal. A failed write with a broken pipe or a connection reset was instead recorded as a local close. That held the terminal for 30 seconds instead of 250ms, so a quick reconnect was refused.
What Changed
relay-socket-peer-close.ts: counts a close as peer-caused only when the write error, orsocket.errored, isEPIPEorECONNRESET. libuv maps the Windows named-pipe codes to these.ECANCELED,ECONNABORTED, and a bareERR_STREAM_DESTROYEDafter our owndestroy(). We never shorten the grace for a teardown we caused.relay-reconnect-listener.ts: the socket write now detaches the client aspeer-closedbefore settling, both when the write fails and when it writes to an already-errored socket.Why
This is a follow-up from the Windows SSH-host lanes (#24180). On arm64, the write error arrived before end-of-file.
Linked Issue
Part of the Node runtime plan (Phase 2). Stacked on #24180.
Visual Proof
N/A. There's no user interface change.
Testing
A real dispatcher over a Unix socket covers a kernel EPIPE, a reset before close, and our own destroy, which must stay local. Both peer cases fail without the fix.
The classifier has unit tests.
Not tested: a real Windows named pipe (these tests skip on win32).
Out of scope: the relay's stdout client still closes as local.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.