Skip to content

Commit

Permalink
perf: do not reset the ping timeout on each packet
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Jun 18, 2024
1 parent d3f45dc commit d123d84
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions lib/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,14 @@ 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) {
this.onError("invalid heartbeat direction");
return;
}
debug("got ping");
this.pingTimeoutTimer.refresh();
this.sendPacket("pong");
this.emit("heartbeat");
break;
Expand All @@ -158,6 +153,7 @@ export class Socket extends EventEmitter {
return;
}
debug("got pong");
clearTimeout(this.pingTimeoutTimer);
this.pingIntervalTimer.refresh();
this.emit("heartbeat");
break;
Expand Down

0 comments on commit d123d84

Please sign in to comment.