Jest: write EPIPE when using ChildProcessWorker.js

Created on 8 Jun 2020  ·  9Comments  ·  Source: facebook/jest

🐛 Bug Report

events.js:292

      throw er; // Unhandled 'error' event

      ^



Error: write EPIPE

    at ChildProcess.target._send (internal/child_process.js:806:20)

    at ChildProcess.target.send (internal/child_process.js:677:19)

    at ChildProcessWorker.send (/home/circleci/app/node_modules/jest-worker/build/workers/ChildProcessWorker.js:291:17)

    at WorkerPool.send (/home/circleci/app/node_modules/jest-worker/build/WorkerPool.js:32:34)

    at Farm._process (/home/circleci/app/node_modules/jest-worker/build/Farm.js:129:10)

    at Farm._enqueue (/home/circleci/app/node_modules/jest-worker/build/Farm.js:152:10)

    at Farm._push (/home/circleci/app/node_modules/jest-worker/build/Farm.js:159:12)

    at /home/circleci/app/node_modules/jest-worker/build/Farm.js:90:14

    at new Promise (<anonymous>)

    at Farm.doWork (/home/circleci/app/node_modules/jest-worker/build/Farm.js:56:12)

Emitted 'error' event on ChildProcess instance at:

    at internal/child_process.js:810:39

    at processTicksAndRejections (internal/process/task_queues.js:79:11) {

  errno: 'EPIPE',

  code: 'EPIPE',

  syscall: 'write'

}

error Command failed with exit code 1.

We run our tests in CircleCI using maxWorker=4

For some tests ChildProcessWorker.send fails and break all the tests execution

To Reproduce

Try to run many tests at the same time

Expected behavior

It should not break

Link to repl or repo (highly encouraged)

our internal repo is similar to this one https://github.com/entria/entria-fullstack/tree/master/packages/server
We use a mongodb memory server to run tests.

envinfo

System:
    OS: macOS 10.15.4
    CPU: (4) x64 Intel(R) Core(TM) i7-5557U CPU @ 3.10GHz
  Binaries:
    Node: 12.18.0 - ~/.nvm/versions/node/v12.18.0/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.4 - ~/.nvm/versions/node/v12.18.0/bin/npm
  npmPackages:
    jest: 26.0.1 => 26.0.1 

it can be related to https://github.com/facebook/jest/issues/8507
not sure if this is node version specific

Bug Report Needs Repro Needs Triage

Most helpful comment

I met a similar issue like this when I ran jest --coverage

os: win10 LTSC 2019 (updated to latest)
node: 10.19.0
jest: 26.0.1 ( and tried 25.5.4)
yarn: 1.22.4

Test Suites: 1 skipped, 165 passed, 165 of 476 total
Tests:       67 skipped, 3372 passed, 3439 total
Snapshots:   31 passed, 31 total
Time:        223sevents.js:174
      throw er; // Unhandled 'error' event
      ^

Error: write EPIPE
    at ChildProcess.target._send (internal/child_process.js:762:20)
    at ChildProcess.target.send (internal/child_process.js:634:19)
    at ChildProcessWorker.send (C:\src\web-2nd\node_modules\jest-worker\build\workers\ChildProcessWorker.js:291:17)
    at WorkerPool.send (C:\src\web-2nd\node_modules\jest-worker\build\WorkerPool.js:32:34)
    at Farm._process (C:\src\web-2nd\node_modules\jest-worker\build\Farm.js:129:10)
    at Farm._enqueue (C:\src\web-2nd\node_modules\jest-worker\build\Farm.js:152:10)
    at Farm._push (C:\src\web-2nd\node_modules\jest-worker\build\Farm.js:159:12)
    at Promise (C:\src\web-2nd\node_modules\jest-worker\build\Farm.js:90:14)
    at new Promise (<anonymous>)
    at Farm.doWork (C:\src\web-2nd\node_modules\jest-worker\build\Farm.js:56:12)
Emitted 'error' event at:
    at process.nextTick (internal/child_process.js:766:39)
    at process._tickCallback (internal/process/next_tick.js:61:11)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

All 9 comments

Also encountering this after upgrading from node 10 to 12, and upgrading from jest 23 to 26.

  System:
    OS: macOS 10.15.4
    CPU: (8) x64 Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz
  Binaries:
    Node: 12.16.3 - ~/.nvm/versions/node/v12.16.3/bin/node
    Yarn: 1.22.4 - ~/.nvm/versions/node/v12.16.3/bin/yarn
    npm: 6.14.4 - ~/.nvm/versions/node/v12.16.3/bin/npm
  npmPackages:
    jest: 26.0.1 => 26.0.1 

This has been happening to me as well randomly but as of today, it is constant. Probable cause is adding more tests. No Node or Jest updates occurred.

I met a similar issue like this when I ran jest --coverage

os: win10 LTSC 2019 (updated to latest)
node: 10.19.0
jest: 26.0.1 ( and tried 25.5.4)
yarn: 1.22.4

Test Suites: 1 skipped, 165 passed, 165 of 476 total
Tests:       67 skipped, 3372 passed, 3439 total
Snapshots:   31 passed, 31 total
Time:        223sevents.js:174
      throw er; // Unhandled 'error' event
      ^

Error: write EPIPE
    at ChildProcess.target._send (internal/child_process.js:762:20)
    at ChildProcess.target.send (internal/child_process.js:634:19)
    at ChildProcessWorker.send (C:\src\web-2nd\node_modules\jest-worker\build\workers\ChildProcessWorker.js:291:17)
    at WorkerPool.send (C:\src\web-2nd\node_modules\jest-worker\build\WorkerPool.js:32:34)
    at Farm._process (C:\src\web-2nd\node_modules\jest-worker\build\Farm.js:129:10)
    at Farm._enqueue (C:\src\web-2nd\node_modules\jest-worker\build\Farm.js:152:10)
    at Farm._push (C:\src\web-2nd\node_modules\jest-worker\build\Farm.js:159:12)
    at Promise (C:\src\web-2nd\node_modules\jest-worker\build\Farm.js:90:14)
    at new Promise (<anonymous>)
    at Farm.doWork (C:\src\web-2nd\node_modules\jest-worker\build\Farm.js:56:12)
Emitted 'error' event at:
    at process.nextTick (internal/child_process.js:766:39)
    at process._tickCallback (internal/process/next_tick.js:61:11)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I met a similar issue also when running jest --coverage, it happens randomly
os: win10 version 1909
node: 12.18.0
jest: 26.0.1
npm: 6.14.4
`
Snapshot Summary
ÔÇ║ 1 snapshot failed from 1 test suite. Inspect your code changes or re-run jest with -u to update them.

Test Suites: 1 failed, 16 passed, 17 total
Tests: 1 failed, 71 passed, 72 total
Snapshots: 1 failed, 9 passed, 10 total
Time: 23.033 s
Ran all test suites.

events.js:292
throw er; // Unhandled 'error' event
^

Error: write EPIPE
at ChildProcess.target._send (internal/child_process.js:806:20)
at ChildProcess.target.send (internal/child_process.js:677:19)
at ChildProcess. (C:\Users\ddn4292\Projets\MQ\WEBAPP\webcomponents-detentionnode_modules\@stencil\core\dev-server\index.js:183:13)
at ChildProcess.emit (events.js:315:20)
at emit (internal/child_process.js:876:12)
at processTicksAndRejections (internal/process/task_queues.js:85:21)
Emitted 'error' event on ChildProcess instance at:
at internal/child_process.js:810:39
at processTicksAndRejections (internal/process/task_queues.js:79:11) {
errno: 'EPIPE',
code: 'EPIPE',
syscall: 'write'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test: stencil test --spec --e2e --coverage
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\ddn4292\AppData\Roaming\npm-cache_logs\2020-09-11T19_23_58_027Z-debug.log
`

I deleted the coverage folder and re-ran it and the error went away.

Unexpected, the same without --verbose flag.

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'test' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'pretest', 'test', 'posttest' ]
5 info lifecycle [email protected]~pretest: [email protected]
6 info lifecycle [email protected]~test: [email protected]
7 verbose lifecycle [email protected]~test: unsafe-perm in lifecycle true
10 silly lifecycle [email protected]~test: Args: [ '-c', 'jest --verbose ./src/core' ]
11 silly lifecycle [email protected]~test: Returned: code: 1  signal: null
12 info lifecycle [email protected]~test: Failed to exec test script
13 verbose stack Error: [email protected] test: `jest --verbose ./src/core`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:321:20)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:321:20)
13 verbose stack     at maybeClose (internal/child_process.js:1026:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid [email protected]
15 verbose cwd /home/userFolder/Kribamine/core
16 verbose **Linux 4.9.0-13-amd64**
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "test"
18 verbose **node v13.9.0**
19 verbose npm  v6.13.7
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] test: `jest --verbose ./src/core`
22 error Exit status 1
23 error Failed at the [email protected] test script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

We're getting this error on a 3G VM but it builds successfully on a 7G VM:

 18:14:29.2938 > set NODE_OPTIONS=--max-old-space-size=2048 && react-scripts build
 18:14:29.2938 
 18:14:30.3562 Creating an optimized production build...
 18:17:19.5046 events.js:291
 18:17:19.5060       throw er; // Unhandled 'error' event
 18:17:19.5060       ^
 18:17:19.5060 
 18:17:19.5060 Error: write EPIPE
 18:17:19.5060     at ChildProcess.target._send (internal/child_process.js:831:20)
 18:17:19.5060     at ChildProcess.target.send (internal/child_process.js:702:19)
 18:17:19.5060     at ChildProcessWorker.send (/inventory-ui/node_modules/terser-webpack-plugin/node_modules/jest-worker/build/workers/ChildProcessWorker.js:291:17)
 18:17:19.5060     at WorkerPool.send (/inventory-ui/node_modules/terser-webpack-plugin/node_modules/jest-worker/build/WorkerPool.js:32:34)
 18:17:19.5060     at Farm._process (/inventory-ui/node_modules/terser-webpack-plugin/node_modules/jest-worker/build/Farm.js:129:10)
 18:17:19.5060     at Farm._enqueue (/inventory-ui/node_modules/terser-webpack-plugin/node_modules/jest-worker/build/Farm.js:152:10)
 18:17:19.5060     at Farm._push (/inventory-ui/node_modules/terser-webpack-plugin/node_modules/jest-worker/build/Farm.js:159:12)
 18:17:19.5060     at /inventory-ui/node_modules/terser-webpack-plugin/node_modules/jest-worker/build/Farm.js:90:14
 18:17:19.5060     at new Promise (<anonymous>)
 18:17:19.5060     at Farm.doWork (/inventory-ui/node_modules/terser-webpack-plugin/node_modules/jest-worker/build/Farm.js:56:12)
 18:17:19.5060     at JestWorker._callFunctionWithArgs (/inventory-ui/node_modules/terser-webpack-plugin/node_modules/jest-worker/build/index.js:143:23)
 18:17:19.5060     at TaskRunner.runTask (/inventory-ui/node_modules/terser-webpack-plugin/dist/TaskRunner.js:41:26)
 18:17:19.5061     at enqueue (/inventory-ui/node_modules/terser-webpack-plugin/dist/TaskRunner.js:89:35)
 18:17:19.5061     at /inventory-ui/node_modules/terser-webpack-plugin/dist/TaskRunner.js:113:86
 18:17:19.5061 Emitted 'error' event on ChildProcess instance at:
 18:17:19.5061     at internal/child_process.js:835:39
 18:17:19.5061     at processTicksAndRejections (internal/process/task_queues.js:75:11) {
 18:17:19.5061   errno: -32,
 18:17:19.5061   code: 'EPIPE',
 18:17:19.5061   syscall: 'write'
 18:17:19.5061 }

this happens when your tests have memory leak

One of the main cause of this error is when your code throws an error and the error isn't caught.

Look for places in the code that call 'Throw new Error()' or promise.reject() or promise failures from incorrectly stubbed unit tests. Try to handle these errors in catch block somewhere higher up instead of bubbling up uncaught.

Was this page helpful?
0 / 5 - 0 ratings