diff --git a/packages/socket.io/lib/index.ts b/packages/socket.io/lib/index.ts index 1ccb4bfd49..396169314f 100644 --- a/packages/socket.io/lib/index.ts +++ b/packages/socket.io/lib/index.ts @@ -746,14 +746,16 @@ export class Server< * * @param [fn] optional, called as `fn([err])` on error OR all conns closed */ - public close(fn?: (err?: Error) => void): void { - this._nsps.forEach((nsp) => { - nsp.sockets.forEach((socket) => { - socket._onclose("server shutting down"); - }); - - nsp.adapter.close(); - }); + public async close(fn?: (err?: Error) => void): Promise { + await Promise.allSettled( + [...this._nsps.values()].map(async (nsp) => { + nsp.sockets.forEach((socket) => { + socket._onclose("server shutting down"); + }); + + await nsp.adapter.close(); + }) + ); this.engine.close();