🚀 Feature Proposal
When running Jest, the following warning may appear:
A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --detectOpenHandles to find leaks.
In some cases, the worker process may not have enough time to exit gracefully due to system load or resource constraints. The issue originates in the BaseWorkerPool.js file, where the FORCE_EXIT_DELAY constant is hardcoded to 500 milliseconds:
...
const FORCE_EXIT_DELAY = 500;
...
// Schedule a force exit in case worker fails to exit gracefully so
// await worker.waitForExit() never takes longer than FORCE_EXIT_DELAY
let forceExited = false;
const forceExitTimeout = setTimeout(() => {
worker.forceExit();
forceExited = true;
}, FORCE_EXIT_DELAY);
await worker.waitForExit();
// Worker ideally exited gracefully, don't send force exit then
clearTimeout(forceExitTimeout);
return forceExited;
...
The current hardcoded delay may be insufficient in some environments, causing unnecessary forced exits and misleading warnings.
Motivation
In resource-constrained environments, such as CI/CD pipelines or heavily-loaded systems, workers may require more than 500 milliseconds to exit gracefully. Increasing the FORCE_EXIT_DELAY in these scenarios prevents misleading warnings and unnecessary forced exits, improving the overall testing experience.
The message ...
A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --detectOpenHandles to find leaks.
... can be especially misleading in these cases. A more accurate message would state the time threshold explicitly and provide a way to adjust it, such as:
A worker process has failed to exit gracefully within 500 milliseconds and has been force exited. This could indicate test leaks or insufficient teardown time. Try running with --detectOpenHandles or increase the forced exit threshold with the --forceExitDelay option.
Example
This feature would allow users to configure the FORCE_EXIT_DELAY value either via CLI:
jest --forceExitDelay:2500
... or in jest.config.js:
module.exports = {
forceExitDelay:2500 // time in ms, so 2.5 seconds here
};
Pitch
The proposed feature improves test reliability in environments where workers may need more time to exit gracefully. Without this feature, users may encounter misleading warnings or forced exits, even in properly functioning setups.
Manually modifying FORCE_EXIT_DELAY in BaseWorkerPool.js has been shown to resolve these issues consistently. Making this configurable would empower users to fine-tune their setups without altering Jest's source code.
🚀 Feature Proposal
When running Jest, the following warning may appear:
A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --detectOpenHandles to find leaks.In some cases, the worker process may not have enough time to exit gracefully due to system load or resource constraints. The issue originates in the
BaseWorkerPool.jsfile, where theFORCE_EXIT_DELAYconstant is hardcoded to500milliseconds:The current hardcoded delay may be insufficient in some environments, causing unnecessary forced exits and misleading warnings.
Motivation
In resource-constrained environments, such as CI/CD pipelines or heavily-loaded systems, workers may require more than 500 milliseconds to exit gracefully. Increasing the FORCE_EXIT_DELAY in these scenarios prevents misleading warnings and unnecessary forced exits, improving the overall testing experience.
The message ...
A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --detectOpenHandles to find leaks.... can be especially misleading in these cases. A more accurate message would state the time threshold explicitly and provide a way to adjust it, such as:
A worker process has failed to exit gracefully within 500 milliseconds and has been force exited. This could indicate test leaks or insufficient teardown time. Try running with --detectOpenHandles or increase the forced exit threshold with the --forceExitDelay option.Example
This feature would allow users to configure the
FORCE_EXIT_DELAYvalue either via CLI:jest --forceExitDelay:2500... or in
jest.config.js:Pitch
The proposed feature improves test reliability in environments where workers may need more time to exit gracefully. Without this feature, users may encounter misleading warnings or forced exits, even in properly functioning setups.
Manually modifying
FORCE_EXIT_DELAYinBaseWorkerPool.jshas been shown to resolve these issues consistently. Making this configurable would empower users to fine-tune their setups without altering Jest's source code.