Skip to content

fix: handle ASGI WebSocket close events and environment propagation - #218

Open
dom96 wants to merge 1 commit into
mainfrom
dominik/ws-close-env
Open

fix: handle ASGI WebSocket close events and environment propagation#218
dom96 wants to merge 1 commit into
mainfrom
dominik/ws-close-env

Conversation

@dom96

@dom96 dom96 commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

This fixes two gaps in ASGI WebSocket handling:

  • Application-originated websocket.close messages were ignored, so clients never received the requested close code or reason.
  • WebSocket scopes always received an empty env, even when the caller supplied Worker bindings.

Test Plan

$ uv run pytest 'tests/test_in_workerd.py::test_in_workerd[asgi-ws-disconnect-3.13]' -v

@dom96
dom96 requested a review from ryanking13 August 18, 2026 18:05
@ask-bonk

ask-bonk Bot commented Aug 18, 2026

Copy link
Copy Markdown

ProviderModelNotFoundError

github run

@ask-bonk

ask-bonk Bot commented Aug 18, 2026

Copy link
Copy Markdown

@dom96 Bonk workflow failed. Check the logs for details.

View workflow run · To retry, trigger Bonk again.

Comment on lines +372 to +374
if got["type"] == "websocket.close":
server.close(got.get("code", 1000), got.get("reason", ""))
return

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.

This partially overlaps with #166, but I think we can merge this first and #166 can be rebased to handle app task ends event only (cc: @whitphx)

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