Skip to content

Commit

Permalink
add config.keepaliveForce
Browse files Browse the repository at this point in the history
Why?

If you have ever worked with web3 subscriptions, in particular with infura's node, you will stop receiving messages after a few minutes of inactivity.

When a subscription its established for example a subscription to logs, there would be only incomming messages from the node.

The package currently doesn't ping if messages are being received.

I propose adding this option keepaliveForce, that would force the keepalive to be sent

Here you can see workarounds that need to be done, but could be solved if this option its enabled

https://medium.com/@pauloostenrijk/infura-drops-your-websocket-connections-after-a-while-and-here-is-a-fix-for-it-3413ca8253b
  • Loading branch information
gerardo15 authored Jul 4, 2021
1 parent a2cd306 commit 0075432
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/WebSocketConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ WebSocketConnection.prototype.handleGracePeriodTimer = function() {
WebSocketConnection.prototype.handleSocketData = function(data) {
this._debug('handleSocketData');
// Reset the keepalive timer when receiving data of any kind.
this.setKeepaliveTimer();
if (!this.config.keepaliveForce) {
this.setKeepaliveTimer();
}

// Add received data to our bufferList, which efficiently holds received
// data chunks in a linked list of Buffer objects.
Expand Down

0 comments on commit 0075432

Please sign in to comment.