Skip to content

fix(jest-worker): skip idle memory check after worker END - #16475

Open
00200200 wants to merge 3 commits into
jestjs:mainfrom
00200200:fix/jest-worker-end-epipe
Open

00200200 wants to merge 3 commits into
jestjs:mainfrom
00200200:fix/jest-worker-end-epipe

Conversation

@00200200

Copy link
Copy Markdown

Summary

Fixes #16474.

When workerIdleMemoryLimit is set, Jest never runs in-band, so every run ends workers through CHILD_MESSAGE_END. That message is answered by the child exiting, not by a reply, so _request is still set when _onExit runs.

If Node emits exit before disconnect, _child.connected is still true and _onProcessEnd calls checkMemoryUsage(), which writes to a half-closed IPC channel:

Unable to check memory usage Error: write EPIPE

The same path restarts the worker when idleMemoryLimit is 0. Skip both the memory check and that restart when the pending request is CHILD_MESSAGE_END.

Test plan

  • Added unit tests in packages/jest-worker/src/workers/__tests__/ChildProcessWorker.test.ts that force the race (connected === true on exit after CHILD_MESSAGE_END) for a normal idle limit and for idleMemoryLimit: 0.
  • Confirmed those two tests fail on current main and pass with this change.
  • yarn jest packages/jest-worker/src/workers/__tests__/ChildProcessWorker.test.ts packages/jest-worker/src/__tests__/process-integration.test.ts packages/jest-worker/src/workers/__tests__/WorkerEdgeCases.test.ts

CHILD_MESSAGE_END is answered by the child exiting, not by a reply. Treating it like a finished call raced with shutdown and printed write EPIPE when workerIdleMemoryLimit was set.
@linux-foundation-easycla

linux-foundation-easycla Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

CLA Not Signed

@netlify

netlify Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for jestjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 882f355
🔍 Latest deploy log https://app.netlify.com/projects/jestjs/deploys/6abba7458d480b0008d0df3b
😎 Deploy Preview https://deploy-preview-16475--jestjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

@github-actions github-actions Bot added the require-changelog If a PR does requires a changelog entry label Sep 29, 2026
@pkg-pr-new

pkg-pr-new Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

babel-jest

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

babel-plugin-jest-hoist

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

babel-preset-jest

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

create-jest

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

@jest/diff-sequences

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

expect

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

@jest/expect-utils

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

jest

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

jest-changed-files

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

jest-circus

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

jest-cli

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

jest-config

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

@jest/console

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

@jest/core

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

@jest/create-cache-key-function

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

jest-diff

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

jest-docblock

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

jest-each

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

@jest/environment

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

jest-environment-jsdom

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

@jest/environment-jsdom-abstract

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

jest-environment-node

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

@jest/expect

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

@jest/fake-timers

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

@jest/get-type

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

@jest/globals

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

jest-haste-map

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

jest-jasmine2

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

jest-leak-detector

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

jest-matcher-utils

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

jest-message-util

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

jest-mock

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

@jest/pattern

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

jest-phabricator

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

jest-regex-util

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

@jest/reporters

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

jest-resolve

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

jest-resolve-dependencies

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

jest-runner

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

jest-runtime

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

@jest/schemas

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

jest-snapshot

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

@jest/snapshot-utils

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

@jest/source-map

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

@jest/test-result

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

@jest/test-sequencer

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

@jest/transform

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

@jest/types

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

jest-util

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

jest-validate

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

jest-watcher

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

jest-worker

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

pretty-format

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

commit: 882f355

This branch has not been deployed

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

Labels

require-changelog If a PR does requires a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: intermittant "Unable to check memory usage Error: write EPIPE" when running one test when workerIdleMemoryLimit option is set

1 participant