Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Websocket.close() meaning of "close status: XXXXX" #414

Closed
wkyle opened this issue Mar 21, 2018 · 2 comments
Closed

Websocket.close() meaning of "close status: XXXXX" #414

wkyle opened this issue Mar 21, 2018 · 2 comments

Comments

@wkyle
Copy link

wkyle commented Mar 21, 2018

When I close a websocket object I get status codes printed to the console. They're raised as a result of a non-"STATUS_NORMAL" status:

recv_status = struct.unpack("!H", frame.data[0:2])[0]
if recv_status != STATUS_NORMAL:
    error("close status: " + repr(recv_status))

Is there a dictionary somewhere on what each code means?

@wkyle
Copy link
Author

wkyle commented Mar 22, 2018

Or perhaps I can get a more verbose error message pointing me to the problem?

@shmal
Copy link

shmal commented Apr 11, 2018

status codes are in the websocket/_abnf.py file (or you could lookup RFC 6455). Are you receiving a valid status code number or part of the body of the next message received?

This is the behavior that I am seeing and I think is a bug in the close implementation (_core.py).

close() sends an OPCODE_CLOSE to the other end of the connection and then immediately reads a new frame and expects it to also be an OPCODE_CLOSE. This is not guaranteed and could be any other valid message (in my case, I get OPCODE_TEXT or OPCODE_PING). Ping has no payload so the recv_status line you posted throws an exception that is caught a few lines later and the close continues (no error message).

If I get an OPCODE_TEXT, the recv_status line grabs the first 2 bytes of my text message and converts it to an invalid opcode (31496, etc), and then displays the error.

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

No branches or pull requests

2 participants