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 is already in CLOSING or CLOSED state. ERROR #592
Comments
Some gateway, routing nodes, such as firewalls will close the TCP connection that does not communicate for a long time(for example, 60 seconds), which leads to application communication failure. So we need to add a heartbeat to the application layer to keep the connection from being disconnected. In JS, ws = new WebSocket('ws://example.com');
ws.onopen = function () {
var t = setInterval(function(){
if (ws.readyState != 1) {
clearInterval(t);
return;
}
ws.send('{type:"ping"}');
}, 55000);
}; When the server receives heartbeat data, it can ignore it and do nothing. Heartbeat interval less than 60 seconds is better, such as 55 seconds. |
May be It will help. But If I open my website(websocket) in the same browser with two similar tabs and start clicking (checking websocket work) on the first and on the second (and reload this) , then I'll get this error too. I changed interval for a 5 seconds and it didn't affect. WebSocket is already in CLOSING or CLOSED state |
WebSocket is already in CLOSING or CLOSED state means that the connection has been disconnected and data cannot be sent through this connection. In addition to the lack of heartbeat and being disconnected by the network node, it is also possible that the client or server called the close method, and there may be a bug in your business code. |
The problem is not with connection anymore. The problem with multiple tabs. When 1 user open 15 tabs, then connection will lose. I found an answer on stackoverflow about this issue. Link https://stackoverflow.com/questions/59176767/socket-io-with-multiple-tabs-not-working-and-when-refreshing-the-page I check connection variable and found out, that workerId has not unique id. And it possible affected on this error. |
Is the problem solved? |
Yes, the problem was with my code (sql requests). Also your documentation is small |
please my webterm shows disconnected...terminado and goes on to show websocket closed, how do i fix this? |
|
how may you help me who has just started a software engineering course and i still don't know how to write a "c" or "js" script |
unable access git hub resources,. its said disconnected or closed |
how do i get back to where i stopped when the web socket closes automatically? |
I'm faced with new error a few hours later. If I open my website, then connection will open. But If I switch tabs in my browser after 5 minutes, I'll get this error WebSocket is already in CLOSING or CLOSED state in my webbrowser's console and lose connection
I'm surfed the Internet and found a solution, that I should set PingTimeOut option on a client side. But how can I do this...
Also I seen Timer in the Workerman, but I'm doubt about relating this to my issue, because no information.
Similar Issue socketio/socket.io#3259
The text was updated successfully, but these errors were encountered: