Skip to content

Commit

Permalink
feat: increase the default value of pingTimeout
Browse files Browse the repository at this point in the history
This value was updated from 60000 to 5000 in [1], included in
`[email protected]` (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]: 65b1ad1

Related:

- socketio/socket.io#2770
- socketio/socket.io#2769
- socketio/socket.io#3054
- socketio/socket.io#3376
  • Loading branch information
darrachequesne committed Mar 2, 2021
1 parent 9534355 commit 5a7fa13
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
2 changes: 1 addition & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5a7fa13

Please sign in to comment.