fix: call closeAllConnections() before server.close()

server.close() only stops accepting new connections but does not
terminate existing keep-alive connections. This can cause the cleanup
promise to hang indefinitely in test suites or production.

Add server.closeAllConnections() (Node.js 18.2+) before server.close()
in both single-account and bulk cleanup paths.

Addresses greptile review feedback.
This commit is contained in:
elliotllliu 2026-03-21 04:15:21 +00:00
parent 569f2c803d
commit 7c1d33521b

View File

@ -137,6 +137,7 @@ export function stopFeishuMonitorState(accountId?: string): void {
wsClients.delete(accountId);
const server = httpServers.get(accountId);
if (server) {
server.closeAllConnections();
server.close();
httpServers.delete(accountId);
}
@ -147,6 +148,7 @@ export function stopFeishuMonitorState(accountId?: string): void {
wsClients.clear();
for (const server of httpServers.values()) {
server.closeAllConnections();
server.close();
}
httpServers.clear();