Skip to content

Commit c1a33db

Browse files
committed
Fixed keep alive frequency for long timeouts
1 parent 63d5b76 commit c1a33db

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "jsonrpc-bidirectional",
33
"description": "Bidirectional JSONRPC over web sockets or HTTP with extensive plugin support.",
4-
"version": "9.6.5",
4+
"version": "9.7.0",
55
"scripts": {
66
"build": "node --experimental-worker build.js",
77
"prepublish": "node --experimental-worker build.js && node --expose-gc --max-old-space-size=1024 --experimental-worker tests/main.js",

src/Plugins/Client/WebSocketTransport.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class WebSocketTransport extends JSONRPC.ClientPluginBase
6868
* MUST set the .rpc() bSkipWaitReadyOnConnect param (or .rpcX({skipWaitReadyOnConnect})) to true or else the call will hang forever.
6969
*
7070
*
71-
* A WebSocket ping control frame (most efficient way to ping for a WebSocket) is sent at an interval (nKeepAliveTimeoutMilliseconds / 2) by the server side (if configured to do so using a non-null nKeepAliveTimeoutMilliseconds).
71+
* A WebSocket ping control frame (most efficient way to ping for a WebSocket) is sent at an interval (the smallest of nKeepAliveTimeoutMilliseconds / 2 or 4000 milliseconds) by the server side (if configured to do so using a non-null nKeepAliveTimeoutMilliseconds).
7272
* The client checks (if configured to do so using a non-null nKeepAliveTimeoutMilliseconds) if a ping was received since connecting or since the last ping (whichever came last).
7373
* If the ping (or pong for compatibility with other keep alive systems in other libraries) control frame is not seen by the client for nKeepAliveTimeoutMilliseconds then the client will close its WebSocket.
7474
* If the pong (or ping for compatibility with other keep alive systems in other libraries) control frame is not seen by the server for nKeepAliveTimeoutMilliseconds then the server will close its WebSocket.
@@ -206,7 +206,7 @@ class WebSocketTransport extends JSONRPC.ClientPluginBase
206206
{
207207
this._nIntervalIDSendKeepAlivePing = setInterval(() => {
208208
webSocket.ping(fnNoop);
209-
}, Math.max(1, Math.floor(this._nKeepAliveTimeoutMilliseconds / 2)));
209+
}, Math.max(1, Math.min(4000, Math.floor(this._nKeepAliveTimeoutMilliseconds / 2))));
210210
}
211211

212212
const fnOnKeepAlive = (() => {

0 commit comments

Comments
 (0)