Skip to content

Commit 1f5d469

Browse files
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: socketio/socket.io-client-swift#1309 (comment) Backported from ff2b8ab
1 parent 3ad0567 commit 1f5d469

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/socket.js

-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ Socket.prototype.maybeUpgrade = function (transport) {
208208
self.clearTransport();
209209
self.setTransport(transport);
210210
self.emit('upgrade', transport);
211-
self.setPingTimeout();
212211
self.flush();
213212
if (self.readyState === 'closing') {
214213
transport.close(function () {

test/server.js

+18
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,24 @@ describe('server', function () {
10921092
});
10931093
});
10941094

1095+
it('should not timeout after an upgrade', done => {
1096+
const opts = { pingInterval: 200, pingTimeout: 20 };
1097+
const engine = listen(opts, port => {
1098+
const socket = new eioc.Socket('ws://localhost:%d'.s(port));
1099+
socket.on('open', () => {
1100+
setTimeout(() => {
1101+
socket.removeListener('close');
1102+
engine.close();
1103+
socket.close();
1104+
done();
1105+
}, 500);
1106+
});
1107+
socket.on('close', () => {
1108+
done(new Error('should not happen'));
1109+
});
1110+
});
1111+
});
1112+
10951113
it('should not crash when messing with Object prototype', function (done) {
10961114
Object.prototype.foo = 'bar'; // eslint-disable-line no-extend-native
10971115
var engine = listen({ allowUpgrades: true }, function (port) {

0 commit comments

Comments
 (0)