Skip to content

fix(server): cancel pending ws calls when the connection closes - #1656

Merged
bkchr merged 4 commits into
paritytech:masterfrom
mattsse:mattsse/ws-cancel-calls-on-close
Sep 30, 2026
Merged

bkchr merged 4 commits into
paritytech:masterfrom
mattsse:mattsse/ws-cancel-calls-on-close

Conversation

@mattsse

@mattsse mattsse commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Every WebSocket call runs on its own spawned task that is not tied to the connection. When the connection closes, these tasks keep running until the method returns, and the response is then discarded. For expensive methods this means a client that disconnects or times out leaves the work running on the server with no way to cancel it, unlike HTTP where hyper drops the service future when the client goes away.

The call is now raced against MethodSink::closed, which resolves once the connection's send task exits, so the method future is dropped when the connection is gone. Graceful shutdown still drains pending calls because the send task keeps running until they are done, and subscriptions are unaffected since their tasks are spawned separately.

WebSocket calls run on detached tasks, so a closed connection left them
running to completion with nobody to send the response to.
@bkchr
bkchr merged commit eaedfef into paritytech:master Sep 30, 2026
11 checks 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.

2 participants