Skip to content

fix(runtime-sdk): implement WebSocket close semantics and app-task lifetime - #166

Open
whitphx wants to merge 1 commit into
cloudflare:mainfrom
whitphx:fix/asgi-ws-close-and-task-lifecycle
Open

fix(runtime-sdk): implement WebSocket close semantics and app-task lifetime#166
whitphx wants to merge 1 commit into
cloudflare:mainfrom
whitphx:fix/asgi-ws-close-and-task-lifecycle

Conversation

@whitphx

@whitphx whitphx commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Three related gaps in process_websocket:

  1. App-initiated websocket.close is "Not implemented": the app's close message only logged a warning, so app-initiated closes left the client connection half-open.
  2. The app task is not registered with the runtime: process_request passes its task to wait_until, but process_websocket only used run_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).
  3. No transport shutdown when the app task ends without 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-ws in packages/runtime-sdk runs the workerd suite, which covers the app-close and crash paths.

@whitphx
whitphx force-pushed the fix/asgi-ws-close-and-task-lifecycle branch 2 times, most recently from 250feb9 to fa0acfc Compare August 10, 2026 05:22
…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
whitphx force-pushed the fix/asgi-ws-close-and-task-lifecycle branch from fa0acfc to 667afe1 Compare August 11, 2026 06:35
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