From b2d94026c4f98af1cc6f96263cb119e245ed6a47 Mon Sep 17 00:00:00 2001 From: Felix Kaminski Date: Sat, 19 Aug 2023 12:38:47 +0200 Subject: [PATCH] fix: exposes stuck services during shutdown timeout --- src/app/ApplicationBuilder.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/app/ApplicationBuilder.ts b/src/app/ApplicationBuilder.ts index f890306..7360e55 100644 --- a/src/app/ApplicationBuilder.ts +++ b/src/app/ApplicationBuilder.ts @@ -607,17 +607,31 @@ export class ApplicationBuilder { ); try { + const shutdownServices = new Set(this.servicesWithLifecycleHandlers); await Promise.race([ sleep(this.appBuilderConfig.shutdownGracePeriodSeconds * 1000, true).then(() => { const error = new Error("Timeout while graceful-shutdown, will exit now"); - this.rootLogger.error({ reason }, error.message); + this.rootLogger.error( + { + remainingServicesWithLifecycleHandlers: Array.from(shutdownServices).map( + s => s.constructor.name, + ), + reason, + }, + error.message, + ); if (this.appBuilderConfig.exitAfterRun) { process.exit(1); } else { throw error; } }), - Promise.all(this.servicesWithLifecycleHandlers.map(svc => svc.shutdown && svc.shutdown())), + Promise.all( + this.servicesWithLifecycleHandlers.map(async svc => { + await svc.shutdown?.(); + shutdownServices.delete(svc); + }), + ), ]); debug("Ran all service shutdown handlers"); if (this.appBuilderConfig.exitAfterRun) {