Skip to content

Close the backend request when the client leaves before the WebSocket upgrade completes - #156

Open
zenios wants to merge 1 commit into
eclipse-vertx:mainfrom
zenios:websocket-client-close-before-upgrade
Open

zenios wants to merge 1 commit into
eclipse-vertx:mainfrom
zenios:websocket-client-close-before-upgrade

Conversation

@zenios

@zenios zenios commented Oct 10, 2026

Copy link
Copy Markdown

Fixes #155

Motivation:

The client and backend sockets of a proxied WebSocket are only joined once the backend answers 101. A client that
closes its connection before that leaves the request to the backend open: for as long as the backend does not answer,
and for good when the backend answers 101 after the client has gone ("Handle this case"). A client that is already
gone when the origin is resolved still gets its upgrade sent to the backend.

Changes:

  • Reset the backend request from the client response's exception handler, as ProxiedRequest#sendRequest does for
    proxied HTTP requests. HttpServerResponse calls it with a closed exception only while nothing has been written,
    so it does not fire once the connection has been upgraded.
  • The handler is set before checking closed(), so a client that closed before the origin was resolved (or between
    the two) fails the request without sending the upgrade.
  • When the client connection cannot be upgraded after a 101, close the backend socket instead of printing a stack
    trace.
  • Two tests in WebSocketTest: a client closing during a pending upgrade closes the backend connection, and a client
    gone before the origin is resolved sends no upgrade. Both fail without the change.

… upgrade completes

Motivation:

The client and backend sockets of a proxied WebSocket are only joined once the backend answers 101. A client that
closes its connection before that leaves the request to the backend open: for as long as the backend does not answer,
and for good when the backend answers 101 after the client has gone, since the client connection can no longer be
turned into a socket ("Handle this case"). A client that is already gone when the origin is resolved still gets its
upgrade sent to the backend.

Changes:

Reset the backend request when the client response reports the connection closed before anything was written, the
same way proxied HTTP requests are reset. Fail without sending the upgrade when the client connection is already
closed once the origin is resolved. Close the backend socket instead of printing a stack trace when the client
connection cannot be upgraded after a 101.
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.

WebSocket: backend request left open when the client leaves before the upgrade completes

2 participants