fix(runtime-sdk): implement WebSocket close semantics and app-task lifetime - #166
Open
whitphx wants to merge 1 commit into
Open
fix(runtime-sdk): implement WebSocket close semantics and app-task lifetime#166whitphx wants to merge 1 commit into
whitphx wants to merge 1 commit into
Conversation
whitphx
force-pushed
the
fix/asgi-ws-close-and-task-lifecycle
branch
2 times, most recently
from
August 10, 2026 05:22
250feb9 to
fa0acfc
Compare
…fetime An app-initiated websocket.close only logged a warning, the app task was never registered with the runtime through wait_until, and a task ending after accept without sending close left the transport open. Handle the close message, register the task, and close the transport (1011 on error) when the app ends without doing so.
whitphx
force-pushed
the
fix/asgi-ws-close-and-task-lifecycle
branch
from
August 11, 2026 06:35
fa0acfc to
667afe1
Compare
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.
Three related gaps in
process_websocket:websocket.closeis "Not implemented": the app's close message only logged a warning, so app-initiated closes left the client connection half-open.process_requestpasses its task towait_until, butprocess_websocketonly usedrun_in_background, so the task's lifetime after the 101 is unguaranteed by the platform contract (local wrangler dev happens to keep orphan tasks alive, but that leniency is not documented behavior).websocket.close: per the ASGI spec the server owns closing the transport when the app finishes after accept without sending close (1011 when the task failed). Without this, a crashed handler leaves clients hanging on a half-open connection instead of reconnecting.The close semantics mirror the production-tested behavior of Streamlit-on-Workers' bridge (whitphx/stlite#2077).
pytest -k asgi-wsinpackages/runtime-sdkruns the workerd suite, which covers the app-close and crash paths.