From 1f5d4699862afee1e410fcb0e1f5e751ebcd2f9f Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Tue, 2 Feb 2021 10:27:30 +0100 Subject: [PATCH] fix: do not reset the ping timer after upgrade There was two issues with this behavior: - v3 clients (with allowEIO3: true) were also receiving a "ping" after a successful upgrade, which is incorrect (in v3, it's the client that sends the "ping", and the server answers with a "pong") - the ping timer is not reset after upgrade on the client-side, so an upgrade which took longer than the `pingTimeout` duration could lead to a "ping timeout" error on the client-side I think the latter issue is present since the initial implementation. Related: https://github.com/socketio/socket.io-client-swift/pull/1309#issuecomment-768475704 Backported from https://github.com/socketio/engine.io/commit/ff2b8aba48ebcb0de5626d3b76fddc94c398395f --- lib/socket.js | 1 - test/server.js | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/socket.js b/lib/socket.js index 177b25c69..376e3c1d7 100644 --- a/lib/socket.js +++ b/lib/socket.js @@ -208,7 +208,6 @@ Socket.prototype.maybeUpgrade = function (transport) { self.clearTransport(); self.setTransport(transport); self.emit('upgrade', transport); - self.setPingTimeout(); self.flush(); if (self.readyState === 'closing') { transport.close(function () { diff --git a/test/server.js b/test/server.js index d34f2f235..4954f8ca3 100644 --- a/test/server.js +++ b/test/server.js @@ -1092,6 +1092,24 @@ describe('server', function () { }); }); + it('should not timeout after an upgrade', done => { + const opts = { pingInterval: 200, pingTimeout: 20 }; + const engine = listen(opts, port => { + const socket = new eioc.Socket('ws://localhost:%d'.s(port)); + socket.on('open', () => { + setTimeout(() => { + socket.removeListener('close'); + engine.close(); + socket.close(); + done(); + }, 500); + }); + socket.on('close', () => { + done(new Error('should not happen')); + }); + }); + }); + it('should not crash when messing with Object prototype', function (done) { Object.prototype.foo = 'bar'; // eslint-disable-line no-extend-native var engine = listen({ allowUpgrades: true }, function (port) {