Skip to content

Heartbeat does not work when timeout < interval #270

@zehawki

Description

@zehawki

I recently switched over to the inbuilt heartbeat, but was not able to get it working properly, while my own heartbeat implementation on top has been working fine for long. After various debugging, I narrowed it down to the following:

If timeout < interval, the timeout occurs before the 1st heartbeat is sent, and the WS is closed.

But this is not as per the documentation.

The desc says:

  1. ...the library will send a 'ping' message to the server every interval milliseconds
  2. If no response is received within timeout milliseconds, indicating a potential connection issue, the library will close the connection.

Making it very clear that timeout starts AFTER a ping is sent, which is how it should be, and makes perfect sense.

Whereas, whats going on is that the timeout has already started counting down from the time the last message was received. With setting like:

timeout = 60000 (ie 1min)
interval = 600000 (ie 10 mins)

and the WS idle for just 1 min, the TO expires and closes the WS with a message like hook.js:608 Heartbeat timed out, closing connection, last message received 106046ms ago, last ping sent 106257ms ago.

Rather it should be based on interval. I know when the server will close the WS, so I can set interval accordingly, in this case 10 mins. Every 10min I expect to send a heartbeat, and IF no response comes back within timeout, then it makes sense to close the connection.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions