MCPcopy Create free account
hub / github.com/esmBot/esmBot / sigHandler

Function sigHandler

src/api/index.ts:329–357  ·  view source on GitHub ↗
(signal: NodeJS.Signals)

Source from the content-addressed store, hash-verified

327let stopping = false;
328
329function sigHandler(signal: NodeJS.Signals) {
330 if (stopping) {
331 logger.info(`Another ${signal} detected, forcing shutdown...`);
332 process.exit();
333 }
334 stopping = true;
335 logger.info(`${signal} detected, finishing jobs and shutting down...`);
336 httpServer.removeAllListeners("upgrade");
337 const closeResponse = Buffer.concat([Buffer.from([Rclose])]);
338 for (const client of wss.clients) {
339 client.send(closeResponse);
340 }
341 wss.close((e) => {
342 if (e) {
343 error(e);
344 process.exit(1);
345 }
346 logger.info("Stopped WS server");
347 if (jobs.size > 0) {
348 jobs.delListen((size) => {
349 if (size > 0) return;
350 logger.info("All jobs finished");
351 stopHTTPServer();
352 });
353 } else {
354 stopHTTPServer();
355 }
356 });
357}
358
359process.on("SIGINT", (s) => sigHandler(s));
360process.on("SIGTERM", (s) => sigHandler(s));

Callers 1

index.tsFile · 0.85

Calls 4

stopHTTPServerFunction · 0.85
closeMethod · 0.80
delListenMethod · 0.80
errorFunction · 0.70

Tested by

no test coverage detected