Repository navigation
fix(runtime): don't exit when a client disconnects mid-request - #182
Merged
Merged
Conversation
For POSTs that pass through proxy.ts, Next's body cloning (replaceRequestBody) copies the buffered stream's _events onto the request, dropping its error listeners (vercel/next.js#99278). A client that disconnects before the route re-attaches one makes Node emit an unhandled `Error: aborted` (ECONNRESET). Next's own handler only logs it, but the crash journal handler exited with code 2, so closing a tab with a request in flight could take the server down (reproduced under next dev). Journal these as `client-abort` and keep serving; every other uncaught exception still exits.
…line short Non-Error throws (`throw null`) made the handler itself throw (exit 7, no journal). Client aborts now journal one stackless line so a burst of disconnects cannot rotate real crash records out quickly.
The journal always went to ~/.omp/omp-web, so dev servers and tests run with PI_CODING_AGENT_DIR still wrote the real diagnostics.log. Follow the agent-dir override (same default-agent-dir check as the XDG layout): ~/.omp/omp-web by default, <agent dir>/omp-web when overridden.
andrebrait
force-pushed
the
fix/client-abort-no-exit
branch
from
September 30, 2026 19:26
6b72a2d to
894e890
Compare
kahme247
approved these changes
Oct 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
omp-web's crash handler (
instrumentation.node.ts, from #61) exits with code 2 on everyuncaughtException. A client that disconnects mid-request can surface there asError: aborted(ECONNRESET), so closing a tab with a request in flight could take the server down.Why that error is uncaught: for POST/PUT requests that pass through
proxy.ts, Next's body cloning (replaceRequestBodyinnext/dist/server/body-streams.js) copies the buffered stream's_eventsonto the request, which drops the request'serrorlisteners, Next's own included. If the client disconnects before the route handler attaches a new one, Node emitsabortedwith no listener. This is upstream vercel/next.js#99278 (auto-closed without a fix; no fix PR exists). The code is unchanged in 16.3.8 and 16.4.0-canary.53.Next's own
uncaughtExceptionhandler only logs this.Fix
aborted+ codeECONNRESET) todiagnostics.logas one-lineclient-abortentries and keeps serving.[crash]entry and exits with code 2, including non-Errorthrows.PI_CODING_AGENT_DIR: it stays at~/.omp/omp-web/diagnostics.logby default and moves to<agent dir>/omp-web/when the agent dir is overridden (the same default-agent-dir checklib/omp/paths.tsuses for the XDG layout). Isolated dev servers and tests used to write the real journal.Verification
lib/instrumentation-crash-policy.test.mjsrunsregister()in a child process with an isolatedHOMEand a missing omp binary:client-abort;read ECONNRESET,aborted by peer, a different code) plusnullandundefinedstill exit with code 2.~/.omp/omp-webuntouched, while the default agent dir still uses~/.omp/omp-web;next dev(fresh server, page load, 40 POSTs to/api/omp-updateaborted at random times):client-abortentries with no[crash].next start, some with artificial event-loop stalls, never reproduced the crash on the base code either, so production exposure appears low.tsc --noEmitpasses and eslint passes on the changed files.npm test: 902 pass, 1 fail. The failure iscomponents/MessageView.test.mjs, a load-timing flake that passes when run alone; this PR doesn't touch that file.