Do not raise deferred connection error as uncaught exception after GOAWAY - #1769
Open
immomo808 wants to merge 2 commits into
Open
Do not raise deferred connection error as uncaught exception after GOAWAY#1769immomo808 wants to merge 2 commits into
immomo808 wants to merge 2 commits into
Conversation
…AWAY When a GOAWAY frame with NO_ERROR arrives on a connection without open streams, the session manager destroys the connection with a ConnectError. Node.js defers this error until the socket has closed, and raises it as an "error" event on the session. If the manager exits the "ready" state before the socket has closed - for example because a new request sees the destroyed connection and reconnects - onExitState() removes the manager's error listeners, and the deferred error is raised as an uncaught exception, crashing the process. This can be reproduced with a load balancer that recycles idle connections (observed with GCP and AWS application load balancers, which send GOAWAY after their idle timeout), when a request arrives while the destroyed connection's socket is still closing. Attach a listener to swallow the deferred error, following the same pattern already used in abort(). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: immomo808 <git@immomo808.com>
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.
Fixes #1768.
When a GOAWAY frame with
NO_ERRORarrives on a connection without open streams, the session manager destroys the connection with aConnectError. Node.js defers this error until the socket has closed, and raises it as an"error"event on the session.If the manager exits the "ready" state before the socket has closed — for example because a new request sees the destroyed connection and reconnects —
onExitState()removes the manager's error listeners, and the deferred error is raised as an uncaught exception, crashing the process:We hit this in production behind a GCP internal Application Load Balancer, which sends GOAWAY on idle connections after ~10 minutes (AWS ALBs behave the same way, see #1545).
The fix attaches a listener to swallow the deferred error, following the same pattern already used in
abort().The regression test reproduces the crash deterministically: without the fix, it fails with
failureType: 'uncaughtException'and the error above; with the fix, it passes. The full connect-node test suite passes.🤖 Generated with Claude Code