From bf64870957e626a73e0544716a1a41a4ba5093bb Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Fri, 23 Feb 2024 11:37:12 +0100 Subject: [PATCH] fix: close the adapters when the server is closed Related: - https://github.com/socketio/socket.io-mongo-adapter/issues/9 - https://github.com/socketio/socket.io-postgres-adapter/issues/13 - https://github.com/socketio/socket.io-adapter/commit/0e23ff0cc671e3186510f7cfb8a4c1147457296f --- lib/index.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index bd77218318..60ab00c4eb 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -742,13 +742,17 @@ export class Server< * @param [fn] optional, called as `fn([err])` on error OR all conns closed */ public close(fn?: (err?: Error) => void): void { - for (const socket of this.sockets.sockets.values()) { - socket._onclose("server shutting down"); - } + this._nsps.forEach((nsp) => { + nsp.sockets.forEach((socket) => { + socket._onclose("server shutting down"); + }); + + nsp.adapter.close(); + }); this.engine.close(); - // restore the Adapter prototype + // restore the Adapter prototype, when the Socket.IO server was attached to a uWebSockets.js server restoreAdapter(); if (this.httpServer) {