From 5a7fa132c442bc1e7eefa1cf38168ee951575ded Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Tue, 2 Mar 2021 08:49:58 +0100 Subject: [PATCH] feat: increase the default value of pingTimeout This value was updated from 60000 to 5000 in [1], included in `engine.io@3.2.0` (Feb 2018). The reasoning back then: Some users experienced long delays between disconnection on the server-side and on the client-side. The "disconnect" event would take a long time to fire in the browser, probably due to a timer being delayed. Hence the change. That being said, the current value (5s) now causes unexpected disconnections when a big payload is sent over a slow network, because it prevents the ping-pong packets from being exchanged between the client and the server. This can also happen when a synchronous task blocks the server for more than 5 seconds. The new value (20s) thus seems like a good balance between quick disconnection detection and tolerance to various delays. Note: pingInterval + pingTimeout is still below the threshold of React Native, which complains if a timer is set with a delay of more than 1 minute. [1]: https://github.com/socketio/engine.io/commit/65b1ad1b8a95fb0547ee3f286c1b7da299c7735a Related: - https://github.com/socketio/socket.io/issues/2770 - https://github.com/socketio/socket.io/issues/2769 - https://github.com/socketio/socket.io/issues/3054 - https://github.com/socketio/socket.io/issues/3376 --- README.md | 2 +- lib/server.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8f68afe6a..3a24e6e0b 100644 --- a/README.md +++ b/README.md @@ -222,7 +222,7 @@ to a single process. - `Object`: optional, options object - **Options** - `pingTimeout` (`Number`): how many ms without a pong packet to - consider the connection closed (`5000`) + consider the connection closed (`20000`) - `pingInterval` (`Number`): how many ms before sending a new ping packet (`25000`) - `upgradeTimeout` (`Number`): how many ms before an uncompleted transport upgrade is cancelled (`10000`) diff --git a/lib/server.js b/lib/server.js index a7007357c..644d6b9ef 100644 --- a/lib/server.js +++ b/lib/server.js @@ -23,7 +23,7 @@ class Server extends EventEmitter { this.opts = Object.assign( { wsEngine: process.env.EIO_WS_ENGINE || "ws", - pingTimeout: 5000, + pingTimeout: 20000, pingInterval: 25000, upgradeTimeout: 10000, maxHttpBufferSize: 1e6,