Skip to content

Commit

Permalink
fix(ws): close existing connections
Browse files Browse the repository at this point in the history
Existing connections must be closed manually. Otherwise, application shutdown hangs when shutdown hooks are enabled and there are existing connections.
  • Loading branch information
bettercalljason committed May 3, 2024
1 parent 1db72fd commit 6893058
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/platform-ws/adapters/ws-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@ export class WsAdapter extends AbstractWsAdapter {
client.on(CLOSE_EVENT, callback);
}

public async close(server: any) {
const closeEventSignal = new Promise((resolve, reject) =>
server.close(err => (err ? reject(err) : resolve(undefined))),
);
for (const ws of server.clients) {
ws.terminate();
}
await closeEventSignal;
}

public async dispose() {
const closeEventSignals = Array.from(this.httpServersRegistry)
.filter(([port]) => port !== UNDERLYING_HTTP_SERVER_PORT)
Expand Down

0 comments on commit 6893058

Please sign in to comment.