Attempt to close with local-only codes (e.g. 1006) results in normal close (1000)

Open
#182 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
python
Domain
networking

Research direction

Start at src/wsproto/frame_protocol.py lines 576-577 and trace how an attempted close with code 1006 is handled. Confirm the WebSocket protocol's expected behavior for local-only close codes, then define a regression test showing that 1006 is not converted into a normal 1000 closure.

Written by the indexing model from the issue text.

Description

Currently, if you close a websocket with code 1006 (which is not allowed), the result is a 1000-code closure:
https://github.com/python-hyper/wsproto/blob/main/src/wsproto/frame_protocol.py#L576-L577

I suspect this should instead be either a 1002 error or an exception, but I'm not certain.

This resulted in a latent bug in hypercorn (an ASGI web server that uses wsproto) where websockets were closed with code 1000 on internal server errors:
https://github.com/pgjones/hypercorn/pull/112

Dominant language
Python
Stars
303
Forks
57
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from python-hyper/wsproto

All issues in python-hyper/wsproto

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.