reconnecting-websocket icon indicating copy to clipboard operation
reconnecting-websocket copied to clipboard

Heartbeat check supprortment

Open RolkerMan opened this issue 6 years ago • 8 comments

It seems that the library determines to reconnect by listening to the close() event . Based on a test in chrome, in a case when you cut the internet connection, the close event would be triggered after about 50 seconds. That's to long for the app to start reconneting websocket and notifying users. So, I think it's crucial to provide a heatcheck api which helps checks whether the websocket was disconnected in time. Are there any misunderstandings I have on the reconnecting-websocket library or is heartbeat check already supported?

RolkerMan avatar Dec 12 '18 01:12 RolkerMan

In node JS environment, using ReconnectigWebsocket does not detect 'close' event if i pull out network cable. Also 'ping' method is unsupported, therefore one cannot create heartbeat system easily. Hopefully this feature will be added in the future, i find it important and probably others as well. If the purpose of the library is to handle reconnections, it should handle as much cases as possible, also network disconnects i believe. Otherwise it would be a solid library, but right now i will have to switch back to standard WebSocket library and implement heartbeat (ping/pong) myself. It won't be as robust probably, so it is a pitty :/

teneon avatar Apr 09 '19 09:04 teneon

What API do you propose for this?

maybe a new option like:

{
    heartbeat: {message: 'ping', delay: 5000, timeout: 1000},
}

This would send a "ping" message after 5000 ms of inactivity and, if no response is received after 1000 ms, tries to reconnect.

Any server response could be considered as a valid response to clear interval (this proves the connection is up)

pladaria avatar Aug 29 '19 06:08 pladaria

need this feature

yuu2lee4 avatar Sep 18 '19 07:09 yuu2lee4

What API do you propose for this?

maybe a new option like:

{
    heartbeat: {message: 'ping', delay: 5000, timeout: 1000},
}

This would send a "ping" message after 5000 ms of inactivity and, if no response is received after 1000 ms, tries to reconnect.

Any server response could be considered as a valid response to clear interval (this proves the connection is up)

would be a useful one!

RolkerMan avatar Nov 27 '19 07:11 RolkerMan

Anything new on this? Would be great to remove some extra boilerplate.

rpocase avatar Apr 27 '20 13:04 rpocase

{ heartbeat: {message: 'ping', delay: 5000, timeout: 1000}, }


This would send a "ping" message after 5000 ms of inactivity and, if no response is received after 1000 ms, tries to reconnect.

Are you talking about sending a regular message containing the "ping" string, or sending a ping ICMP message? There is a slight controversy on which one is the correct solution to send keepalives / heartbeats: pings should be the "normal" way but they only detect if the connection is up, they don't detect if the server is actually responsive. Also, the browser's built-in WebSocket implementation does not expose the ping method.

Any server response could be considered as a valid response to clear interval (this proves the connection is up)

Many servers rely on ICMP ping / pong to periodically check and and make sure the client is still connected. These pings should be handled just in the same way as regular messages since they indicate the connection is still fine. However, as mentioned above, not all WebSocket implementations support listening to pings.

This library exposes the ping / pong methods: https://github.com/websockets/ws

Other than this, I subscribe that this would be a great feature.

hernyo avatar Jun 05 '20 05:06 hernyo

any progress on this issue?

happy15 avatar Feb 17 '21 02:02 happy15

I'm trying to use this to connect to Binance, but i think the lack of a ping response is resulting in my connection stopping (https://binance-docs.github.io/apidocs/spot/en/#websocket-market-streams)

npomfret avatar Apr 05 '21 16:04 npomfret