Skip to content

Handle reserved WebSocket close codes in proxy#259

Open
iori0311 wants to merge 1 commit intocloudflare:mainfrom
iori0311:fix/websocket-close-code-forwarding
Open

Handle reserved WebSocket close codes in proxy#259
iori0311 wants to merge 1 commit intocloudflare:mainfrom
iori0311:fix/websocket-close-code-forwarding

Conversation

@iori0311
Copy link

@iori0311 iori0311 commented Feb 16, 2026

This fixes a WebSocket proxy crash caused by forwarding reserved close codes.

In production I saw close code 1006 coming from one side of the proxy. The current code forwards that code directly with ws.close(event.code, ...), which throws because 1006 is reserved and must not be sent in a close frame.

What changed:

  • add close-code validation for outbound close frames
  • use a safe fallback code when the incoming code is not sendable
  • reuse the same safe close path in close/error handlers

Result:

  • no more TypeError: Invalid WebSocket close code: 1006
  • proxy no longer hangs after this failure mode

Validation:

  • npm run typecheck

Fixes #260

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.

WebSocket proxy throws when forwarding reserved close code 1006

1 participant

Comments