Skip to content

Commit 115a981

Browse files
refactor: do not include the pid by default
So that the client knows whether the connection state recovery feature is enabled. See also: 54d5ee0
1 parent 0c0eb00 commit 115a981

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/socket.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,9 @@ export class Socket<
275275
} else {
276276
this.id = base64id.generateId(); // don't reuse the Engine.IO id because it's sensitive information
277277
}
278-
this.pid = base64id.generateId();
278+
if (this.server._opts.connectionStateRecovery) {
279+
this.pid = base64id.generateId();
280+
}
279281
}
280282
this.handshake = this.buildHandshake(auth);
281283
}

test/connection-state-recovery.ts

+22
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,26 @@ describe("connection state recovery", () => {
193193

194194
io.close();
195195
});
196+
197+
it("should be disabled by default", async () => {
198+
const httpServer = createServer().listen(0);
199+
const io = new Server(httpServer);
200+
201+
// Engine.IO handshake
202+
const sid = await eioHandshake(httpServer);
203+
204+
// Socket.IO handshake
205+
await eioPush(httpServer, sid, "40");
206+
207+
const handshakeBody = await eioPoll(httpServer, sid);
208+
209+
expect(handshakeBody.startsWith("40")).to.be(true);
210+
211+
const handshake = JSON.parse(handshakeBody.substring(2));
212+
213+
expect(handshake.sid).to.not.be(undefined);
214+
expect(handshake.pid).to.be(undefined);
215+
216+
io.close();
217+
});
196218
});

0 commit comments

Comments
 (0)