Skip to content

Commit ff2b8ab

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)
1 parent e5b307c commit ff2b8ab

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
@@ -237,7 +237,6 @@ class Socket extends EventEmitter {
237237
self.clearTransport();
238238
self.setTransport(transport);
239239
self.emit("upgrade", transport);
240-
self.schedulePing();
241240
self.flush();
242241
if (self.readyState === "closing") {
243242
transport.close(function() {

test/server.js

+18
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,24 @@ describe("server", () => {
12821282
});
12831283
});
12841284

1285+
it("should not timeout after an upgrade", done => {
1286+
const opts = { pingInterval: 200, pingTimeout: 20 };
1287+
const engine = listen(opts, port => {
1288+
const socket = new eioc.Socket("ws://localhost:%d".s(port));
1289+
socket.on("open", () => {
1290+
setTimeout(() => {
1291+
socket.removeListener("close");
1292+
engine.close();
1293+
socket.close();
1294+
done();
1295+
}, 500);
1296+
});
1297+
socket.on("close", () => {
1298+
done(new Error("should not happen"));
1299+
});
1300+
});
1301+
});
1302+
12851303
it("should not crash when messing with Object prototype", done => {
12861304
Object.prototype.foo = "bar"; // eslint-disable-line no-extend-native
12871305
const engine = listen({ allowUpgrades: true }, port => {

0 commit comments

Comments
 (0)