Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kate/fix env dispose gets stuck #2522

Merged
merged 3 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions packages/core/src/runtime-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,24 @@ export class RuntimeEngine<ENV extends AnyEnvironment = AnyEnvironment> {
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;
Expand Down
16 changes: 7 additions & 9 deletions packages/runtime-node/src/node-env-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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) {
Expand Down Expand Up @@ -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() {
Expand Down