diff --git a/packages/core/src/runtime-engine.ts b/packages/core/src/runtime-engine.ts index d7f5bf789..174bb1942 100644 --- a/packages/core/src/runtime-engine.ts +++ b/packages/core/src/runtime-engine.ts @@ -102,11 +102,24 @@ export class RuntimeEngine { this.running = undefined; const toDispose = Array.from(this.features.values()).reverse(); for (const feature of toDispose) { - await timeout( - feature.dispose(), - this.featureShutdownTimeout, - `Failed to dispose feature: ${feature.feature.id}`, - ); + const startTime = Date.now(); + const intervalId = setInterval(() => { + console.log( + `[${this.entryEnvironment.env}]: Feature ${feature.feature.id} "dispose()" is taking ${( + (Date.now() - startTime) / + 1000 + ).toFixed(2)}s`, + ); + }, 50); + try { + await timeout( + feature.dispose(), + this.featureShutdownTimeout, + `Failed to dispose feature: ${feature.feature.id}`, + ); + } finally { + clearInterval(intervalId); + } } } finally { this.shutingDown = false; diff --git a/packages/runtime-node/src/node-env-manager.ts b/packages/runtime-node/src/node-env-manager.ts index 14fab2e1f..15f7e832a 100644 --- a/packages/runtime-node/src/node-env-manager.ts +++ b/packages/runtime-node/src/node-env-manager.ts @@ -110,7 +110,12 @@ export class NodeEnvManager implements IDisposable { } async closeAll() { - await Promise.all([...this.openEnvironments.values()].map((env) => env.dispose())); + await Promise.all([...this.openEnvironments.values()].map((env) => this.closeEnv(env))); + } + + private closeEnv(env: RunningNodeEnvironment) { + this.openEnvironments.delete(env.id, env); + return env.dispose(); } private async runFeatureEnvironments( @@ -134,11 +139,9 @@ export class NodeEnvManager implements IDisposable { console.log(`[ENGINE]: found the following environments for feature ${featureName}:\n${envNames}`); } - const disposes = await Promise.all( + await Promise.all( envNames.map((envName) => this.initializeWorkerEnvironment(envName, runtimeOptions, host, verbose)), ); - - return () => Promise.all(disposes.map((dispose) => dispose())); } private async loadEnvironmentConfigurations(envName: string, configName: string, verbose = false) { @@ -187,11 +190,6 @@ export class NodeEnvManager implements IDisposable { if (verbose) { console.log(`[ENGINE]: Environment ${runningEnv.id} is ready`); } - - return () => { - this.openEnvironments.delete(envName, runningEnv); - return runningEnv.dispose(); - }; } async collectMetricsFromAllOpenEnvironments() {