Skip to content

feat: add workerGracefulExitTimeout config option#15984

Open
jcwatson11 wants to merge 2 commits intojestjs:mainfrom
jcwatson11:feat/worker-graceful-exit-timeout
Open

feat: add workerGracefulExitTimeout config option#15984
jcwatson11 wants to merge 2 commits intojestjs:mainfrom
jcwatson11:feat/worker-graceful-exit-timeout

Conversation

@jcwatson11
Copy link
Copy Markdown

Summary

  • Add workerGracefulExitTimeout config option (and CLI flag) to control how long worker processes are given to exit gracefully before being force-killed
  • Default remains 500ms, preserving existing behavior
  • Touches jest-worker, jest-config, jest-runner, jest-cli, jest-schemas, and jest-types

Motivation

jest-worker hardcodes FORCE_EXIT_DELAY = 500 ms — the time workers get after all tests complete before being SIGTERM'd. Workers that don't exit in time trigger a "A worker process has failed to exit gracefully" warning. In practice, workers naturally exit in 130–500ms, so the fixed 500ms threshold causes intermittent false-positive warnings under normal load.

Making this configurable lets users tune the threshold for their environment without patching jest-worker.

Relates to #11354
Relates to #15468
Relates to #13139

Test plan

  • Added tests in BaseWorkerPool.test.ts verifying custom timeout is respected and default (500ms) is preserved
  • yarn build passes (type-check clean)
  • All tests pass: jest-worker (152), jest-config (266), jest-runner (15), jest-cli (6)

Add a configurable timeout for how long worker processes are given to
exit gracefully before being force-killed. The previous hardcoded 500ms
delay caused false-positive "failed to exit gracefully" warnings when
workers naturally take close to 500ms to shut down.

The new option defaults to 500 (preserving existing behavior) and can be
set via jest.config.js or --workerGracefulExitTimeout CLI flag.
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 2, 2026

Deploy Preview for jestjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 7583c05
🔍 Latest deploy log https://app.netlify.com/projects/jestjs/deploys/69a6212c29ebfa000888647d
😎 Deploy Preview https://deploy-preview-15984--jestjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Mar 2, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 2, 2026

Open in StackBlitz

babel-jest

npm i https://pkg.pr.new/babel-jest@15984

babel-plugin-jest-hoist

npm i https://pkg.pr.new/babel-plugin-jest-hoist@15984

babel-preset-jest

npm i https://pkg.pr.new/babel-preset-jest@15984

create-jest

npm i https://pkg.pr.new/create-jest@15984

@jest/diff-sequences

npm i https://pkg.pr.new/@jest/diff-sequences@15984

expect

npm i https://pkg.pr.new/expect@15984

@jest/expect-utils

npm i https://pkg.pr.new/@jest/expect-utils@15984

jest

npm i https://pkg.pr.new/jest@15984

jest-changed-files

npm i https://pkg.pr.new/jest-changed-files@15984

jest-circus

npm i https://pkg.pr.new/jest-circus@15984

jest-cli

npm i https://pkg.pr.new/jest-cli@15984

jest-config

npm i https://pkg.pr.new/jest-config@15984

@jest/console

npm i https://pkg.pr.new/@jest/console@15984

@jest/core

npm i https://pkg.pr.new/@jest/core@15984

@jest/create-cache-key-function

npm i https://pkg.pr.new/@jest/create-cache-key-function@15984

jest-diff

npm i https://pkg.pr.new/jest-diff@15984

jest-docblock

npm i https://pkg.pr.new/jest-docblock@15984

jest-each

npm i https://pkg.pr.new/jest-each@15984

@jest/environment

npm i https://pkg.pr.new/@jest/environment@15984

jest-environment-jsdom

npm i https://pkg.pr.new/jest-environment-jsdom@15984

@jest/environment-jsdom-abstract

npm i https://pkg.pr.new/@jest/environment-jsdom-abstract@15984

jest-environment-node

npm i https://pkg.pr.new/jest-environment-node@15984

@jest/expect

npm i https://pkg.pr.new/@jest/expect@15984

@jest/fake-timers

npm i https://pkg.pr.new/@jest/fake-timers@15984

@jest/get-type

npm i https://pkg.pr.new/@jest/get-type@15984

@jest/globals

npm i https://pkg.pr.new/@jest/globals@15984

jest-haste-map

npm i https://pkg.pr.new/jest-haste-map@15984

jest-jasmine2

npm i https://pkg.pr.new/jest-jasmine2@15984

jest-leak-detector

npm i https://pkg.pr.new/jest-leak-detector@15984

jest-matcher-utils

npm i https://pkg.pr.new/jest-matcher-utils@15984

jest-message-util

npm i https://pkg.pr.new/jest-message-util@15984

jest-mock

npm i https://pkg.pr.new/jest-mock@15984

@jest/pattern

npm i https://pkg.pr.new/@jest/pattern@15984

jest-phabricator

npm i https://pkg.pr.new/jest-phabricator@15984

jest-regex-util

npm i https://pkg.pr.new/jest-regex-util@15984

@jest/reporters

npm i https://pkg.pr.new/@jest/reporters@15984

jest-resolve

npm i https://pkg.pr.new/jest-resolve@15984

jest-resolve-dependencies

npm i https://pkg.pr.new/jest-resolve-dependencies@15984

jest-runner

npm i https://pkg.pr.new/jest-runner@15984

jest-runtime

npm i https://pkg.pr.new/jest-runtime@15984

@jest/schemas

npm i https://pkg.pr.new/@jest/schemas@15984

jest-snapshot

npm i https://pkg.pr.new/jest-snapshot@15984

@jest/snapshot-utils

npm i https://pkg.pr.new/@jest/snapshot-utils@15984

@jest/source-map

npm i https://pkg.pr.new/@jest/source-map@15984

@jest/test-result

npm i https://pkg.pr.new/@jest/test-result@15984

@jest/test-sequencer

npm i https://pkg.pr.new/@jest/test-sequencer@15984

@jest/transform

npm i https://pkg.pr.new/@jest/transform@15984

@jest/types

npm i https://pkg.pr.new/@jest/types@15984

jest-util

npm i https://pkg.pr.new/jest-util@15984

jest-validate

npm i https://pkg.pr.new/jest-validate@15984

jest-watcher

npm i https://pkg.pr.new/jest-watcher@15984

jest-worker

npm i https://pkg.pr.new/jest-worker@15984

pretty-format

npm i https://pkg.pr.new/pretty-format@15984

commit: 25a5b2f

- Fix Prettier violation in jest-runner/src/index.ts
- Update showConfig e2e snapshot with new config option
- Revert normalize.test.ts snapshots to match CI color output
@jcwatson11
Copy link
Copy Markdown
Author

The remaining two failing checks (Windows shard 1/4 on Node v24 and Node LTS jest-jasmine2) are unrelated to this PR's changes. They fail on a snapshot in e2e/__tests__/jest.config.ts.test.ts for the on node >=24 › invalid JS in jest.config.ts (node with native TS support) test.

The issue is that the ERR_INVALID_TYPESCRIPT_SYNTAX error message format changed between Node v24 patch versions — the snapshot expects a parenthetical detail after got 'string literal' that newer builds no longer include.

Happy to include a fix in this PR (normalizing that portion of the error message in the test), but also totally understand if you'd prefer to address it separately. Just let me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant