websockets / ws

Simple to use, blazing fast and thoroughly tested WebSocket client and server for Node.js
MIT License
21.54k stars 2.42k forks source link

Calling ping with an interval timer to ping the server on no internet connection results constant "PONG" response after reconnection to internet #1337

Closed Benjamin-Willard closed 6 years ago

Benjamin-Willard commented 6 years ago

I am not sure if this is actually a bug or not. When using ping and there is no response from the server. (With a interval timer to call ping x amount of time). I would get a huge list of "PONG" response after internet establishment again.

So it would be like this in the console log "PING" "Could not connect to Server" "PING" "Could not connect to Server" "PING" "Could not connect to Server" "PING" "Could not connect to Server" "PING" "Could not connect to Server" "PING" "Could not connect to Server" "PING" "Could not connect to Server" "PING" "Could not connect to Server" "PING" "PONG" "PONG" "PONG" "PONG" "PONG" "PONG" "PONG" "PONG" "PONG" "PING" "PONG" "PING" "PONG" "PING" "PONG"

lpinca commented 6 years ago

Can you show some code that reproduces the issue? It shouldn't be possible if the underlying socket is not reused.

lpinca commented 6 years ago

If the connection is not closed but no message can be sent and then all of sudden it start working again, then it's normal as messages are buffered.

Benjamin-Willard commented 6 years ago

Basically what is happening is let's say I am connected via the web socket protocol. And then all of sudden my application looses internet connection. The socket is still open however no data can get through. When internet comes back online it will flood all the ping attempts to the server with a bunch of pong responses. What I did on my end is just check to see if it has pong already and if it has it won't spit out in the console log. However that doesn't stop it from flooding.

It could get ugly as let's say that socket connection is still open on a internet connection that was once online but goes offline. The socket is still online. If I we're to call ping let's say 1 time per second. And I am offline for 60 seconds, it will flood 60 pong response. which might be not to bad but let's say i'm offline 1 hour, that is 3600 pong responses that would flood the CPU and possibly crash the application.

On Tue, Mar 27, 2018 at 12:10 PM, Luigi Pinca notifications@github.com wrote:

If the connection is not closed but no message can be sent and then all of sudden it start working again, then it's normal as messages are buffered.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/websockets/ws/issues/1337#issuecomment-376640673, or mute the thread https://github.com/notifications/unsubscribe-auth/ABef2WoGeteDUJPN9NWFJQIjvb878OjAks5tio6bgaJpZM4S9ck3 .

lpinca commented 6 years ago

Why are you keeping sending pings if they don't go through? If you haven't received a pong I would either force close the connection or clear the interval before sending another ping.

Benjamin-Willard commented 6 years ago

Yup, after realizing I changed how I was doing it. Made it so that if it doesn't get a response from a PONG after n amount of time then it would result terminating that connection/closing it and then allow the "auto-reconnect" logic I have reapply once connection established again.

Thanks!

On Tue, Mar 27, 2018 at 1:05 PM, Luigi Pinca notifications@github.com wrote:

Why are you keeping sending pings if they don't go through? If you haven't received a pong I would either force close the connection or clear the interval before sending another ping.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/websockets/ws/issues/1337#issuecomment-376656760, or mute the thread https://github.com/notifications/unsubscribe-auth/ABef2YxY2zAQFNMZGwNLf55dL-bBybo0ks5tiptygaJpZM4S9ck3 .