MCPcopy
hub / github.com/nestjs/nest / cleanup

Method cleanup

packages/core/nest-application-context.ts:366–397  ·  view source on GitHub ↗
(signal: string)

Source from the content-addressed store, hash-verified

364 ) {
365 let receivedSignal = false;
366 const cleanup = async (signal: string) => {
367 try {
368 if (receivedSignal) {
369 // If we receive another signal while we're waiting
370 // for the server to stop, just ignore it.
371 return;
372 }
373 receivedSignal = true;
374 await this.initializationPromise;
375 await this.callDestroyHook();
376 await this.callBeforeShutdownHook(signal);
377 await this.dispose();
378 await this.callShutdownHook(signal);
379 signals.forEach(sig => process.removeListener(sig, cleanup));
380
381 if (options.useProcessExit) {
382 // Use process.exit() to ensure the 'exit' event is properly triggered.
383 // This is required for async loggers (like Pino with transports)
384 // to flush their buffers before the process terminates.
385 process.exit(0);
386 } else {
387 process.kill(process.pid, signal);
388 }
389 } catch (err) {
390 Logger.error(
391 MESSAGES.ERROR_DURING_SHUTDOWN,
392 (err as Error)?.stack,
393 NestApplicationContext.name,
394 );
395 process.exit(1);
396 }
397 };
398 this.shutdownCleanupRef = cleanup as (...args: unknown[]) => unknown;
399
400 signals.forEach((signal: string) => {

Callers

nothing calls this directly

Calls 5

callDestroyHookMethod · 0.95
disposeMethod · 0.95
callShutdownHookMethod · 0.95
errorMethod · 0.65

Tested by

no test coverage detected