Skip to content

fix(runtime-sdk): deliver client WebSocket close events to the ASGI app - #158

Merged
ryanking13 merged 5 commits into
cloudflare:mainfrom
whitphx:fix/asgi-ws-disconnect-delivery
Jul 30, 2026
Merged

fix(runtime-sdk): deliver client WebSocket close events to the ASGI app#158
ryanking13 merged 5 commits into
cloudflare:mainfrom
whitphx:fix/asgi-ws-disconnect-delivery

Conversation

@whitphx

@whitphx whitphx commented Jul 29, 2026

Copy link
Copy Markdown
Contributor
  • The close handler onclose was wrongly assigned to server.onopen
  • And even with the registration fixed, the enqueued event used the type websocket.close, which per the ASGI spec is the app-to-server direction; client disconnects must arrive as websocket.disconnect as the spec says.

whitphx added 3 commits July 28, 2026 22:37
The close handler was assigned to server.onopen (overwriting the open
handler assigned on the previous line), so close events never reached
the bridge and ASGI apps could never observe client disconnects.
"websocket.close" is the app-to-server message; client disconnects must
arrive at the app as "websocket.disconnect", which is the only type
frameworks translate into their disconnect exceptions (e.g. Starlette's
WebSocketDisconnect).
@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@whitphx

whitphx commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Jul 29, 2026
@whitphx
whitphx force-pushed the fix/asgi-ws-disconnect-delivery branch from 419a2d2 to e7f5b0e Compare July 29, 2026 06:16
@whitphx whitphx changed the title Fix/asgi ws disconnect delivery fix(runtime-sdk): deliver client WebSocket close events to the ASGI app Jul 29, 2026
The asgi-prefixed workerd-test case added on this branch hits the same
known combination the existing asgi case is already excluded for:
pywrangler sync fails to install pyodide packages in the unittest
environment on Linux with the Python 3.12 compat config, so the worker
boots without pytest. Match the exclusion by prefix so asgi-* cases
inherit it.

@ryanking13 ryanking13 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I think we need to improve our test architecture a bit to better support more asgi tests, but the changewise looks good to me.

@ryanking13
ryanking13 merged commit 6f53155 into cloudflare:main Jul 30, 2026
12 checks passed
@whitphx

whitphx commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

@ryanking13 Thanks! I have more changes to propose to this repo in my mind but should I wait for the test architecture improvements to land or skip adding test cases until that?

@whitphx
whitphx deleted the fix/asgi-ws-disconnect-delivery branch July 30, 2026 07:25
@ryanking13

Copy link
Copy Markdown
Contributor

@ryanking13 Thanks! I have more changes to propose to this repo in my mind but should I wait for the test architecture improvements to land or skip adding test cases until that?

You don't need to wait! Those refactor works can go in parallel and you don't need to be blocked by it. It is our job to manage those refactor-chaos not you :)

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