Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions packages/core/src/pool/forks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const createForksPool = (poolOptions: {
execArgv,
maxThreads,
minThreads,
teardown: 'teardown',
concurrentTasksPerWorker: 1,
isolateWorkers: isolate,
};
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/runtime/worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,6 @@ const loadFiles = async ({
});
};

const onExit = () => {
process.exit();
};

const runInPool = async (
options: RunWorkerOptions['options'],
): Promise<
Expand Down Expand Up @@ -294,15 +290,11 @@ const runInPool = async (
process.exit = exit;
});

process.off('SIGTERM', onExit);

const teardown = async () => {
await new Promise((resolve) => getRealTimers().setTimeout!(resolve));

await Promise.all(cleanups.map((fn) => fn()));
isTeardown = true;
// should exit correctly when user's signal listener exists
process.once('SIGTERM', onExit);
};

if (type === 'collect') {
Expand Down Expand Up @@ -428,4 +420,12 @@ const runInPool = async (
}
};

// should be called before worker is terminated
export const teardown = (): void => {
// should exit correctly when user's signal listener exists
process.once('SIGTERM', () => {
process.exit();
});
};

export default runInPool;
Loading