Skip to content

Commit

Permalink
fix(sio): correctly await async close on adapters (#4971)
Browse files Browse the repository at this point in the history
Following: bf64870
  • Loading branch information
marknelissen authored Sep 14, 2024
1 parent b5ccfd4 commit e347a3c
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/socket.io/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
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();

Expand Down

0 comments on commit e347a3c

Please sign in to comment.