uNetworking / uWebSockets.js

μWebSockets for Node.js back-ends :metal:
Apache License 2.0
7.76k stars 563 forks source link

Upgrade is successful and open handler runs but WS disconnects #927

Closed DigitalMachinist closed 1 year ago

DigitalMachinist commented 1 year ago

I'm running uWS v20.30.0 and I've been building a websocket server following the UpgradeAsync example. When a client connects, the upgrade seems to complete and the open handler runs suggesting that the WS connection is up. However, the client is suddenly disconnecting and the close handler reports a code of 1006 (no error message) shortly thereafter.

My understanding is that suggests the client is initiating the disconnect. I read elsewhere that this could be due to the client requesting a subprotocol that causes an issue, but the client is submitting an empty string for sec-websocket-protocol, so I doubt that.

I've also tested this against a web-based WS client and I get similar behaviour. As far as I can tell, the client doesn't record any WS traffic at all before the disconnect. I've tried running this both from inside a docker container and directly off the host OS but the behaviour is the same.

Is there anything I should be checking that might result in this behaviour? Happy to share code if that's helpful.

e3dio commented 1 year ago

You should start by posting minimal example code for both server and client that shows issue, otherwise impossible to say what you are doing wrong

DigitalMachinist commented 1 year ago

I got into stripping this down to provide an example and resolved the issue in the process.

Apparently I was setting some CORS headers in the upgrade response, which I thought made sense to do, but they were the cause of the breakdown. After they were removed, everything worked smoothly.

I appreciate the help, although I'm sorry for taking your time just to play rubber duck. Thanks for the great software. I'll close the issue.

Have a good one!