uNetworking / uWebSockets.js

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

Error events? #210

Closed ghost closed 4 years ago

ghost commented 5 years ago

Everyone got disconnected from websocket server suddenly, it happened few times. The normal disconnects sets reason string so I know whats going on but in this case it wasn't set. Is there any way to debug this like listening on error events? The Node.js app didnt crash itself nor log anything so I got no clue what could've gone wrong. I used Uws v16.0.0 in in Debian 9 with Node.js v12. I saw that the 16.1.0 had some pub/sub crash fix but I dont use subscribe/unsubscribe functions so I assume thats not related? Also if there is some problem with Uws will it print something? Thanks

ghost commented 5 years ago

There are only a few reasons for disconnections, and the graceful ones are reported as such, like you wrote.

All other disconnections are essentially due to protocol errors (broken clients) or various timeouts.

You have idleTimeout default to 120 seconds, so you need to either set it to 0 (disabled) or make sure to ping the server regularly.

You also have maxBackpressure default to something like 1MB or so, also something you can look at.

Other than that, of course the server won't crash - that would be entirely unacceptable.

ghost commented 5 years ago

It was weird because everyone got disconnected at same time after being connected for awhile. Is there any situation where this would be possible? My client sends messages (only binary) multiple times per second. Is the idleTimeout based on websocket ping packets or any messages?

ghost commented 5 years ago

Are you using SSLApp?

ghost commented 5 years ago

yes

ghost commented 5 years ago

Sounds like https://github.com/uNetworking/uSockets/issues/43

ghost commented 5 years ago

Looks like that indeed is the case. I tried connecting to the wss server with 2 tabs and closing the other connection with ws.end(); in code and both tabs got disconnected. I tried it with reason and code arg as well and same happened but only kicked client received the reason but both disconnected. However ws.close() doesn't have this problem. I am on Windows 10 with Node v12.12 and some self-signed certificates for Uws.

ghost commented 5 years ago

Great, I'll see if I can reproduce it

ghost commented 5 years ago

I still cannot reproduce the problem but I made an attempt at fixing the issue,

Could you please try and see if you can reproduce it with npm install uNetworking/uWebSockets.js#binaries

as of today

ghost commented 4 years ago

Yeah that one has the issue fixed on Windows! I assume its working the same way on debian now as well? What was causing it btw?

ghost commented 4 years ago

Great. Thanks for testing. OpenSSL functions can sometimes create side effects (sigh) where global per thread state is changed and needs to be cleared for the following calls to be reliable