Skip to content

fix(graphql): close upgrade sockets that no listener claims - #4236

Merged
kamilmysliwiec merged 1 commit into
masterfrom
fix/close-unclaimed-upgrade-sockets
Nov 12, 2026
Merged

kamilmysliwiec merged 1 commit into
masterfrom
fix/close-unclaimed-upgrade-sockets

Conversation

@kamilmysliwiec

Copy link
Copy Markdown
Member

PR Checklist

  • The commit message follows our guidelines
  • Tests for the changes have been added
  • Docs have been added / updated

PR Type

  • Bugfix

What is the current behavior?

When another upgrade listener shares the HTTP server, the subscriptions listener leaves upgrade requests for other paths to it. @nestjs/platform-ws now follows the same rule (nestjs/nest#18501), so with both installed an upgrade for a path that neither serves is closed by nobody. The HTTP server's timeouts no longer apply after upgrade, so the socket stays open until the client hangs up.

What is the new behavior?

Such a socket is closed after a second if nothing has been written to it since the upgrade, the same as in nestjs/nest#18501. The delay is set with a new unclaimedUpgradeTimeout option in the graphql-ws config, for another listener that answers the handshake late (for example after a slow authentication); 0 turns the timer off. The count is taken at the upgrade, since a keep-alive connection that answered earlier requests already has bytes written.

Checked with real sockets as well: /graphql still upgrades, and an unknown path is closed after about a second, both on a fresh connection and after a plain request on the same one.

Does this PR introduce a breaking change?

  • Yes
  • No

When another upgrade listener shares the HTTP server, an upgrade for a
path that neither serves was left open until the client hung up, as each
listener left it to the other. Close it once nothing has been written to
it for a second (unclaimedUpgradeTimeout), as @nestjs/platform-ws does.
@kamilmysliwiec
kamilmysliwiec merged commit 670b4b1 into master Nov 12, 2026
1 check passed
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.

1 participant