From 28573b603a7b6076289f8d7de9ef896c86a8d909 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Tue, 9 Apr 2024 20:05:16 +0200 Subject: [PATCH] cleanup and test --- lib/manager.ts | 11 ++++++----- lib/socket.ts | 2 +- test/connection.ts | 13 +++++++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lib/manager.ts b/lib/manager.ts index 6f77f823..acb26ee0 100644 --- a/lib/manager.ts +++ b/lib/manager.ts @@ -473,17 +473,18 @@ export class Manager< /** * Called upon a socket close. * - * @param socket + * @param nsp - the namespace of the socket being closed * @private */ - _destroy(closingSocket: Socket): void { - delete this.nsps[closingSocket.nsp]; + _destroy(nsp: string): void { + delete this.nsps[nsp]; + const nsps = Object.keys(this.nsps); for (const nsp of nsps) { - const socket = this.nsps[nsp]; + const remainingSocket = this.nsps[nsp]; - if (socket.active) { + if (remainingSocket.active) { debug("socket %s is still active, skipping close", nsp); return; } diff --git a/lib/socket.ts b/lib/socket.ts index e65ab4dd..ca3af706 100644 --- a/lib/socket.ts +++ b/lib/socket.ts @@ -881,7 +881,7 @@ export class Socket< this.subs.forEach((subDestroy) => subDestroy()); this.subs = undefined; } - this.io["_destroy"](this); + this.io._destroy(this.nsp); } /** diff --git a/test/connection.ts b/test/connection.ts index 7b36c4f3..0986f834 100644 --- a/test/connection.ts +++ b/test/connection.ts @@ -60,6 +60,19 @@ describe("connection", () => { s2.disconnect(); }); + it("should start a single connection with different namespaces (after disconnection)", () => { + const s1 = io("/foo"); + const s2 = io("/bar"); + + s2.disconnect(); + + const s3 = io("/bar"); + + expect(s3.io).to.be(s1.io); + s1.disconnect(); + s3.disconnect(); + }); + it("should work with acks", () => { return wrap((done) => { const socket = io(BASE_URL, { forceNew: true });