From d123d84cf58aea90a95e9bd78d27fcc3b9959ecb Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Tue, 18 Jun 2024 17:14:41 +0200 Subject: [PATCH] perf: do not reset the ping timeout on each packet --- lib/socket.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/socket.ts b/lib/socket.ts index 300fcb19..8c35b7a3 100644 --- a/lib/socket.ts +++ b/lib/socket.ts @@ -135,12 +135,6 @@ export class Socket extends EventEmitter { debug(`received packet ${packet.type}`); this.emit("packet", packet); - // Reset ping timeout on any packet, incoming data is a good sign of - // other side's liveness - this.resetPingTimeout( - this.server.opts.pingInterval + this.server.opts.pingTimeout - ); - switch (packet.type) { case "ping": if (this.transport.protocol !== 3) { @@ -148,6 +142,7 @@ export class Socket extends EventEmitter { return; } debug("got ping"); + this.pingTimeoutTimer.refresh(); this.sendPacket("pong"); this.emit("heartbeat"); break; @@ -158,6 +153,7 @@ export class Socket extends EventEmitter { return; } debug("got pong"); + clearTimeout(this.pingTimeoutTimer); this.pingIntervalTimer.refresh(); this.emit("heartbeat"); break;