From ff1a13243e2c9eae42cb05fcc61caa5a950d6af3 Mon Sep 17 00:00:00 2001 From: Katerina Zakimatova Date: Tue, 9 Jul 2024 18:17:47 +0200 Subject: [PATCH 1/3] log long disposal time of features --- packages/core/src/runtime-engine.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/core/src/runtime-engine.ts b/packages/core/src/runtime-engine.ts index d7f5bf789..8ae45efe9 100644 --- a/packages/core/src/runtime-engine.ts +++ b/packages/core/src/runtime-engine.ts @@ -102,11 +102,21 @@ export class RuntimeEngine { this.running = undefined; const toDispose = Array.from(this.features.values()).reverse(); for (const feature of toDispose) { + 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); await timeout( feature.dispose(), this.featureShutdownTimeout, `Failed to dispose feature: ${feature.feature.id}`, ); + clearInterval(intervalId); } } finally { this.shutingDown = false; From ee840b1951a45afa48c653cf0708e669b9c531d0 Mon Sep 17 00:00:00 2001 From: Katerina Zakimatova Date: Tue, 9 Jul 2024 18:18:50 +0200 Subject: [PATCH 2/3] fix: env was in runningEnvs after its disposal --- packages/runtime-node/src/node-env-manager.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) 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() { From 9214038805d7489cf319069d5ac5074290822ad6 Mon Sep 17 00:00:00 2001 From: Katerina Zakimatova Date: Wed, 10 Jul 2024 12:03:57 +0200 Subject: [PATCH 3/3] make sure dispose log interval gets cleared when dispose rejects the promise --- packages/core/src/runtime-engine.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/core/src/runtime-engine.ts b/packages/core/src/runtime-engine.ts index 8ae45efe9..174bb1942 100644 --- a/packages/core/src/runtime-engine.ts +++ b/packages/core/src/runtime-engine.ts @@ -111,12 +111,15 @@ export class RuntimeEngine { ).toFixed(2)}s`, ); }, 50); - await timeout( - feature.dispose(), - this.featureShutdownTimeout, - `Failed to dispose feature: ${feature.feature.id}`, - ); - clearInterval(intervalId); + try { + await timeout( + feature.dispose(), + this.featureShutdownTimeout, + `Failed to dispose feature: ${feature.feature.id}`, + ); + } finally { + clearInterval(intervalId); + } } } finally { this.shutingDown = false;