Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug?]: workspaces foreach using too much memory #3395

Open
1 task
LaurensUP opened this issue Sep 6, 2021 · 6 comments
Open
1 task

[Bug?]: workspaces foreach using too much memory #3395

LaurensUP opened this issue Sep 6, 2021 · 6 comments
Labels
bug Something isn't working upholded Real issues without formal reproduction

Comments

@LaurensUP
Copy link

LaurensUP commented Sep 6, 2021

Self-service

  • I'd be willing to implement a fix

Describe the bug

We used to have a custom script building a dependency tree for our monorepo and building packages in the right order.
Since the workspaces plugin does the same thing, we've replaced this script.
However, when running the command on CI, it goes out of memory.

As the workspaces foreach command is essentially doing the same thing as our former JS script, this is unexpected behavior.

Script:
yarn workspaces foreach --topological-dev --parallel --verbose --jobs 4 run build

It also goes out of memory with 2 jobs, while we used to be able to run this with 4 workers.

Output on CI:

15:33:33  ➤ YN0000: [**********]: Internal Error: spawn ENOMEM
15:33:33  ➤ YN0000: [**********]:     at ChildProcess.spawn (internal/child_process.js:403:11)
15:33:33  ➤ YN0000: [**********]:     at spawn (child_process.js:667:9)
15:33:33  ➤ YN0000: [**********]:     at Object.spawnWithSignal [as spawn] (child_process.js:871:17)
15:33:33  ➤ YN0000: [**********]:     at FN (/opt/jenkins/workspace/**********/.yarn/releases/yarn-3.0.0.cjs:4:7428)
15:33:33  ➤ YN0000: [**********]:     at Wf.implementation (/opt/jenkins/workspace/**********/.yarn/releases/yarn-3.0.0.cjs:255:1599)
15:33:33  ➤ YN0000: [**********]:     at Wf.exec (/opt/jenkins/workspace/**********/.yarn/releases/yarn-3.0.0.cjs:258:1582)
15:33:33  ➤ YN0000: [**********]:     at Wf.run (/opt/jenkins/workspace/**********/.yarn/releases/yarn-3.0.0.cjs:258:1753)
15:33:33  ➤ YN0000: [**********]:     at SJ (/opt/jenkins/workspace/**********/.yarn/releases/yarn-3.0.0.cjs:267:6185)
15:33:33  ➤ YN0000: [**********]:     at runMicrotasks (<anonymous>)
15:33:33  ➤ YN0000: [**********]:     at processTicksAndRejections (internal/process/task_queues.js:95:5)
15:33:33  ➤ YN0000: [**********]: Process exited (exit code 1), completed in 28s 273ms
15:33:38  ➤ YN0000: [********************]: [info] [webpackbar] Compiling Webpack
15:33:38  ➤ YN0000: [********************]: [success] [webpackbar] Webpack: Compiled successfully in 28.69s
15:33:38  ➤ YN0000: [********************]: Process exited (exit code 0), completed in 32s 180ms
15:33:38  ➤ YN0000: The command failed for workspaces that are depended upon by other workspaces; can't satisfy the dependency graph
15:33:38  ➤ YN0000: Failed with errors in 4m 7s

To reproduce

Need quite a big monorepo to reproduce this..
If there are ideas for me to set this up, I will try to make a solid reproduce case.

Environment

  System:
    OS: Linux 5.11 Ubuntu 21.04 (Hirsute Hippo)
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
  Binaries:
    Node: 14.17.6 - /tmp/xfs-88fc14e7/node
    Yarn: 3.0.0 - /tmp/xfs-88fc14e7/yarn
    npm: 6.14.15 - ~/.nvm/versions/node/v14.17.6/bin/npm
  npmPackages:
    jest: 27.0.1 => 27.0.1 

Additional context

It seems to me that there is some kind of memory leak when using yarn workspaces foreach on a big monorepo (~80+ packages).

We have a test suite per package, and when running those suites sequentially with workspaces foreach, even those are going out of memory on CI atm.

Edit:
Running the following command on CI:
CI=true yarn workspaces foreach -v run test --silent --passWithNoTests

where test in every workspace is defined like this:
"test": "yarn g:jest"
and the top level command is:
"g:jest": "cd $INIT_CWD && jest"

Goes out of memory as soon as it needs to actually build a test.

Edit2:
Added mem logging on CI. It shows that our machine has plenty of memory available, but still we're getting an ENOMEM error.

Edit 3:
Yarn workspaces is crashing out of the process as soon as it tries to spawn the process.
There is no output from the process or command itself.
The problem seems to be a memory leak in yarn workspaces under the Node env.

Normal CI output:

15:02:34  ➤ YN0000: [***********]: Process started
15:02:38  ➤ YN0000: [***********]: No tests found related to files changed since "upstream/master".
15:02:38  ➤ YN0000: [***********]: Process exited (exit code 0), completed in 3s 130ms
15:02:38  
15:02:38  ➤ YN0000: [***********]: Process started
15:02:41  ➤ YN0000: [***********]: No tests found related to files changed since "upstream/master".
15:02:41  ➤ YN0000: [***********]: Process exited (exit code 0), completed in 3s 151ms
15:02:41  
15:02:41  ➤ YN0000: [***********]: Process started
15:02:43  ➤ YN0000: [***********]: No tests found related to files changed since "upstream/master".
15:02:43  ➤ YN0000: [***********]: Process exited (exit code 0), completed in 2s 939ms
15:02:43  
15:02:43  ➤ YN0000: [***********]: Process started
15:02:47  ➤ YN0000: [***********]: No tests found related to files changed since "upstream/master".
15:02:47  ➤ YN0000: [***********]: Process exited (exit code 0), completed in 2s 922ms
15:02:47  
15:02:47  ➤ YN0000: [***********]: Process started
15:02:49  ➤ YN0000: [***********]: No tests found related to files changed since "upstream/master".
15:02:49  ➤ YN0000: [***********]: Process exited (exit code 0), completed in 2s 941ms
15:02:49  
15:02:49  ➤ YN0000: [***********]: Process started
15:02:52  ➤ YN0000: [***********]: No tests found related to files changed since "upstream/master".
15:02:52  ➤ YN0000: [***********]: Process exited (exit code 0), completed in 2s 929ms
15:02:52  
15:02:52  ➤ YN0000: [***********]: Process started
15:02:55  ➤ YN0000: [***********]: No tests found related to files changed since "upstream/master".
15:02:55  ➤ YN0000: [***********]: Process exited (exit code 0), completed in 2s 957ms
15:02:55  
15:02:55  ➤ YN0000: [***********]: Process started
15:02:56  ➤ YN0000: [***********]: Internal Error: spawn ENOMEM
15:02:56  ➤ YN0000: [***********]:     at ChildProcess.spawn (internal/child_process.js:403:11)
15:02:56  ➤ YN0000: [***********]:     at spawn (child_process.js:667:9)
15:02:56  ➤ YN0000: [***********] (child_process.js:871:17)
15:02:56  ➤ YN0000: [***********]:     at FN (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:4:7428)
15:02:56  ➤ YN0000: [***********]:     at Wf.implementation (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:255:1599)
15:02:56  ➤ YN0000: [***********]:     at Wf.exec (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:258:1582)
15:02:56  ➤ YN0000: [***********]:     at Wf.run (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:258:1753)
15:02:56  ➤ YN0000: [***********]:     at SJ (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:267:6185)
15:02:56  ➤ YN0000: [***********]:     at processTicksAndRejections (internal/process/task_queues.js:95:5)
15:02:56  ➤ YN0000: [***********]:     at async cwe (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:269:16)
15:02:56  ➤ YN0000: [***********]: Process exited (exit code 1), completed in 0s 614ms
15:02:56  
15:02:56  ➤ YN0000: [***********]: Process started
15:02:56  ➤ YN0000: [***********]: Internal Error: spawn ENOMEM
15:02:56  ➤ YN0000: [***********]:     at ChildProcess.spawn (internal/child_process.js:403:11)
15:02:56  ➤ YN0000: [***********]:     at spawn (child_process.js:667:9)
15:02:56  ➤ YN0000: [***********] (child_process.js:871:17)
15:02:56  ➤ YN0000: [***********]:     at FN (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:4:7428)
15:02:56  ➤ YN0000: [***********]:     at Wf.implementation (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:255:1599)
15:02:56  ➤ YN0000: [***********]:     at Wf.exec (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:258:1582)
15:02:56  ➤ YN0000: [***********]:     at Wf.run (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:258:1753)
15:02:56  ➤ YN0000: [***********]:     at SJ (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:267:6185)
15:02:56  ➤ YN0000: [***********]:     at processTicksAndRejections (internal/process/task_queues.js:95:5)
15:02:56  ➤ YN0000: [***********]:     at async cwe (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:269:16)
15:02:56  ➤ YN0000: [***********]: Process exited (exit code 1), completed in 0s 609ms
15:02:56  
15:02:56  ➤ YN0000: [***********]: Process started
15:02:57  ➤ YN0000: [***********]: Internal Error: spawn ENOMEM
15:02:57  ➤ YN0000: [***********]:     at ChildProcess.spawn (internal/child_process.js:403:11)
15:02:57  ➤ YN0000: [***********]:     at spawn (child_process.js:667:9)
15:02:57  ➤ YN0000: [***********] (child_process.js:871:17)
15:02:57  ➤ YN0000: [***********]:     at FN (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:4:7428)
15:02:57  ➤ YN0000: [***********]:     at Wf.implementation (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:255:1599)
15:02:57  ➤ YN0000: [***********]:     at Wf.exec (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:258:1582)
15:02:57  ➤ YN0000: [***********]:     at Wf.run (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:258:1753)
15:02:57  ➤ YN0000: [***********]:     at SJ (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:267:6185)
15:02:57  ➤ YN0000: [***********]:     at processTicksAndRejections (internal/process/task_queues.js:95:5)
15:02:57  ➤ YN0000: [***********]:     at async cwe (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:269:16)
15:02:57  ➤ YN0000: [***********]: Process exited (exit code 1), completed in 0s 602ms
15:02:57  

Our instance has 16GB of ram and 8 CPU cores.
CI output with memory logs:

10:46:13  ➤ YN0000: [*********************]: Bounce:                0 kB
10:46:13  ➤ YN0000: [*********************]: WritebackTmp:          0 kB
10:46:13  ➤ YN0000: [*********************]: CommitLimit:     7974696 kB
10:46:13  ➤ YN0000: [*********************]: Committed_AS:   15881188 kB
10:46:13  ➤ YN0000: [*********************]: VmallocTotal:   34359738367 kB
10:46:13  ➤ YN0000: [*********************]: VmallocUsed:           0 kB
10:46:13  ➤ YN0000: [*********************]: VmallocChunk:          0 kB
10:46:13  ➤ YN0000: [*********************]: HardwareCorrupted:     0 kB
10:46:13  ➤ YN0000: [*********************]: AnonHugePages:         0 kB
10:46:13  ➤ YN0000: [*********************]: ShmemHugePages:        0 kB
10:46:13  ➤ YN0000: [*********************]: ShmemPmdMapped:        0 kB
10:46:13  ➤ YN0000: [*********************]: HugePages_Total:       0
10:46:13  ➤ YN0000: [*********************]: HugePages_Free:        0
10:46:13  ➤ YN0000: [*********************]: HugePages_Rsvd:        0
10:46:13  ➤ YN0000: [*********************]: HugePages_Surp:        0
10:46:13  ➤ YN0000: [*********************]: Hugepagesize:       2048 kB
10:46:13  ➤ YN0000: [*********************]: DirectMap4k:      563108 kB
10:46:13  ➤ YN0000: [*********************]: DirectMap2M:    15732736 kB
10:46:13  ➤ YN0000: [*********************]: DirectMap1G:           0 kB
10:46:13  ➤ YN0000: [*********************]: Process exited (exit code 0), completed in 7s 392ms
10:46:17  ➤ YN0000: [*********************]: MemTotal:       15949392 kB
10:46:17  ➤ YN0000: [*********************]: MemFree:         4651944 kB
10:46:17  ➤ YN0000: [*********************]: MemAvailable:   13654196 kB
10:46:17  ➤ YN0000: [*********************]: Buffers:            2704 kB
10:46:17  ➤ YN0000: [*********************]: Cached:          8292452 kB
10:46:17  ➤ YN0000: [*********************]: SwapCached:            0 kB
10:46:17  ➤ YN0000: [*********************]: Active:          2282148 kB
10:46:17  ➤ YN0000: [*********************]: Inactive:        6744680 kB
10:46:17  ➤ YN0000: [*********************]: Active(anon):     701140 kB
10:46:17  ➤ YN0000: [*********************]: Inactive(anon):      316 kB
10:46:17  ➤ YN0000: [*********************]: Active(file):    1581008 kB
10:46:17  ➤ YN0000: [*********************]: Inactive(file):  6744364 kB
10:46:17  ➤ YN0000: [*********************]: Unevictable:           0 kB
10:46:17  ➤ YN0000: [*********************]: Mlocked:               0 kB
10:46:17  ➤ YN0000: [*********************]: SwapTotal:             0 kB
10:46:17  ➤ YN0000: [*********************]: SwapFree:              0 kB
10:46:17  ➤ YN0000: [*********************]: Dirty:              2484 kB
10:46:17  ➤ YN0000: [*********************]: Writeback:             0 kB
10:46:17  ➤ YN0000: [*********************]: AnonPages:        731452 kB
10:46:17  ➤ YN0000: [*********************]: Mapped:           171320 kB
10:46:17  ➤ YN0000: [*********************]: Shmem:               560 kB
10:46:17  ➤ YN0000: [*********************]: Slab:            1664528 kB
10:46:17  ➤ YN0000: [*********************]: SReclaimable:    1009884 kB
10:46:17  ➤ YN0000: [*********************]: SUnreclaim:       654644 kB
10:46:17  ➤ YN0000: [*********************]: KernelStack:        5256 kB
10:46:17  ➤ YN0000: [*********************]: PageTables:        12868 kB
10:46:17  ➤ YN0000: [*********************]: NFS_Unstable:          0 kB
10:46:17  ➤ YN0000: [*********************]: Bounce:                0 kB
10:46:17  ➤ YN0000: [*********************]: WritebackTmp:          0 kB
10:46:17  ➤ YN0000: [*********************]: CommitLimit:     7974696 kB
10:46:17  ➤ YN0000: [*********************]: Committed_AS:   14346312 kB
10:46:17  ➤ YN0000: [*********************]: VmallocTotal:   34359738367 kB
10:46:17  ➤ YN0000: [*********************]: VmallocUsed:           0 kB
10:46:17  ➤ YN0000: [*********************]: VmallocChunk:          0 kB
10:46:17  ➤ YN0000: [*********************]: HardwareCorrupted:     0 kB
10:46:17  ➤ YN0000: [*********************]: AnonHugePages:         0 kB
10:46:17  ➤ YN0000: [*********************]: ShmemHugePages:        0 kB
10:46:17  ➤ YN0000: [*********************]: ShmemPmdMapped:        0 kB
10:46:17  ➤ YN0000: [*********************]: HugePages_Total:       0
10:46:17  ➤ YN0000: [*********************]: HugePages_Free:        0
10:46:17  ➤ YN0000: [*********************]: HugePages_Rsvd:        0
10:46:17  ➤ YN0000: [*********************]: HugePages_Surp:        0
10:46:17  ➤ YN0000: [*********************]: Hugepagesize:       2048 kB
10:46:17  ➤ YN0000: [*********************]: DirectMap4k:      563108 kB
10:46:17  ➤ YN0000: [*********************]: DirectMap2M:    15732736 kB
10:46:17  ➤ YN0000: [*********************]: DirectMap1G:           0 kB
10:46:17  ➤ YN0000: [*********************]: Process exited (exit code 0), completed in 27s 280ms
10:46:17  ➤ YN0000: [*********************]: Process started
10:46:17  ➤ YN0000: [*********************]: Process started
10:46:17  ➤ YN0000: [*********************]: Process started
10:46:17  ➤ YN0000: [*********************]: Process started
10:46:18  ➤ YN0000: [*********************]: /opt/jenkins/workspace/*********************_PR-1808/packages/*********************
10:46:18  ➤ YN0000: [*********************]: /opt/jenkins/workspace/*********************_PR-1808/packages/*********************
10:46:18  ➤ YN0000: [*********************]: /opt/jenkins/workspace/*********************_PR-1808/packages/*********************
10:46:18  ➤ YN0000: [*********************]: /opt/jenkins/workspace/*********************_PR-1808/packages/*********************
10:46:20  ➤ YN0000: [*********************]: Nothing to bundle
10:46:20  ➤ YN0000: [*********************]: MemTotal:       15949392 kB
10:46:20  ➤ YN0000: [*********************]: MemFree:         4014880 kB
10:46:20  ➤ YN0000: [*********************]: MemAvailable:   13017272 kB
10:46:20  ➤ YN0000: [*********************]: Buffers:            2704 kB
10:46:20  ➤ YN0000: [*********************]: Cached:          8292568 kB
10:46:20  ➤ YN0000: [*********************]: SwapCached:            0 kB
10:46:20  ➤ YN0000: [*********************]: Active:          2905040 kB
10:46:20  ➤ YN0000: [*********************]: Inactive:        6744760 kB
10:46:20  ➤ YN0000: [*********************]: Active(anon):    1324012 kB
10:46:20  ➤ YN0000: [*********************]: Inactive(anon):      316 kB
10:46:20  ➤ YN0000: [*********************]: Active(file):    1581028 kB
10:46:20  ➤ YN0000: [*********************]: Inactive(file):  6744444 kB
10:46:20  ➤ YN0000: [*********************]: Unevictable:           0 kB
10:46:20  ➤ YN0000: [*********************]: Mlocked:               0 kB
10:46:20  ➤ YN0000: [*********************]: SwapTotal:             0 kB
10:46:20  ➤ YN0000: [*********************]: SwapFree:              0 kB
10:46:20  ➤ YN0000: [*********************]: Dirty:              2624 kB
10:46:20  ➤ YN0000: [*********************]: Writeback:             0 kB
10:46:20  ➤ YN0000: [*********************]: AnonPages:       1354060 kB
10:46:20  ➤ YN0000: [*********************]: Mapped:           171476 kB
10:46:20  ➤ YN0000: [*********************]: Shmem:               560 kB
10:46:20  ➤ YN0000: [*********************]: Slab:            1665172 kB
10:46:20  ➤ YN0000: [*********************]: SReclaimable:    1009924 kB
10:46:20  ➤ YN0000: [*********************]: SUnreclaim:       655248 kB
10:46:20  ➤ YN0000: [*********************]: KernelStack:        6656 kB
10:46:20  ➤ YN0000: [*********************]: PageTables:        21416 kB
10:46:20  ➤ YN0000: [*********************]: NFS_Unstable:          0 kB
10:46:20  ➤ YN0000: [*********************]: Bounce:                0 kB
10:46:20  ➤ YN0000: [*********************]: WritebackTmp:          0 kB
10:46:20  ➤ YN0000: [*********************]: CommitLimit:     7974696 kB
10:46:20  ➤ YN0000: [*********************]: Committed_AS:   17673620 kB
10:46:20  ➤ YN0000: [*********************]: VmallocTotal:   34359738367 kB
10:46:20  ➤ YN0000: [*********************]: VmallocUsed:           0 kB
10:46:20  ➤ YN0000: [*********************]: VmallocChunk:          0 kB
10:46:20  ➤ YN0000: [*********************]: HardwareCorrupted:     0 kB
10:46:20  ➤ YN0000: [*********************]: AnonHugePages:         0 kB
10:46:20  ➤ YN0000: [*********************]: ShmemHugePages:        0 kB
10:46:20  ➤ YN0000: [*********************]: ShmemPmdMapped:        0 kB
10:46:20  ➤ YN0000: [*********************]: HugePages_Total:       0
10:46:20  ➤ YN0000: [*********************]: HugePages_Free:        0
10:46:20  ➤ YN0000: [*********************]: HugePages_Rsvd:        0
10:46:20  ➤ YN0000: [*********************]: HugePages_Surp:        0
10:46:20  ➤ YN0000: [*********************]: Hugepagesize:       2048 kB
10:46:20  ➤ YN0000: [*********************]: DirectMap4k:      563108 kB
10:46:20  ➤ YN0000: [*********************]: DirectMap2M:    15732736 kB
10:46:20  ➤ YN0000: [*********************]: DirectMap1G:           0 kB
10:46:20  ➤ YN0000: [*********************]: Process exited (exit code 0), completed in 3s 268ms
10:46:20  ➤ YN0000: [*********************]: Process started
10:46:20  ➤ YN0000: [*********************]: /opt/jenkins/workspace/*********************_PR-1808/packages/*********************
10:46:21  ➤ YN0000: [*********************] Compiling Webpack
10:46:23  ➤ YN0000: [*********************] Using gulpfile /opt/jenkins/workspace/*********************_PR-1808/packages/*********************
10:46:23  ➤ YN0000: [*********************] Starting 'sass'...
10:46:23  ➤ YN0000: [*********************] Starting 'copy_assets'...
10:46:23  ➤ YN0000: [*********************] Finished 'copy_assets' after 101 ms
10:46:23  ➤ YN0000: [*********************] Starting '<anonymous>'...
10:46:23  ➤ YN0000: [*********************] Starting '<anonymous>'...
10:46:23  ➤ YN0000: [*********************] Starting '<anonymous>'...
10:46:23  ➤ YN0000: [*********************] Finished '<anonymous>' after 7.46 ms
10:46:23  ➤ YN0000: [*********************] Finished '<anonymous>' after 30 ms
10:46:23  ➤ YN0000: [*********************] Finished '<anonymous>' after 38 ms
10:46:23  ➤ YN0000: [*********************] Finished 'sass' after 142 ms
10:46:23  ➤ YN0000: [*********************] Compiling Webpack
10:46:31  ➤ YN0000: [*********************]: MemTotal:       15949392 kB
10:46:31  ➤ YN0000: [*********************]: MemFree:         1978304 kB
10:46:31  ➤ YN0000: [*********************]: MemAvailable:   10982604 kB
10:46:31  ➤ YN0000: [*********************]: Buffers:            2704 kB
10:46:31  ➤ YN0000: [*********************]: Cached:          8292924 kB
10:46:31  ➤ YN0000: [*********************]: SwapCached:            0 kB
10:46:31  ➤ YN0000: [*********************]: Active:          4896120 kB
10:46:31  ➤ YN0000: [*********************]: Inactive:        6736020 kB
10:46:31  ➤ YN0000: [*********************]: Active(anon):    3305980 kB
10:46:31  ➤ YN0000: [*********************]: Inactive(anon):      316 kB
10:46:31  ➤ YN0000: [*********************]: Active(file):    1590140 kB
10:46:31  ➤ YN0000: [*********************]: Inactive(file):  6735704 kB
10:46:31  ➤ YN0000: [*********************]: Unevictable:           0 kB
10:46:31  ➤ YN0000: [*********************]: Mlocked:               0 kB
10:46:31  ➤ YN0000: [*********************]: SwapTotal:             0 kB
10:46:31  ➤ YN0000: [*********************]: SwapFree:              0 kB
10:46:31  ➤ YN0000: [*********************]: Dirty:              2976 kB
10:46:31  ➤ YN0000: [*********************]: Writeback:             0 kB
10:46:31  ➤ YN0000: [*********************]: AnonPages:       3336692 kB
10:46:31  ➤ YN0000: [*********************]: Mapped:           171372 kB
10:46:31  ➤ YN0000: [*********************]: Shmem:               560 kB
10:46:31  ➤ YN0000: [*********************]: Slab:            1670784 kB
10:46:31  ➤ YN0000: [*********************]: SReclaimable:    1011456 kB
10:46:31  ➤ YN0000: [*********************]: SUnreclaim:       659328 kB
10:46:31  ➤ YN0000: [*********************]: KernelStack:        7920 kB
10:46:31  ➤ YN0000: [*********************]: PageTables:        47716 kB
10:46:31  ➤ YN0000: [*********************]: NFS_Unstable:          0 kB
10:46:31  ➤ YN0000: [*********************]: Bounce:                0 kB
10:46:31  ➤ YN0000: [*********************]: WritebackTmp:          0 kB
10:46:31  ➤ YN0000: [*********************]: CommitLimit:     7974696 kB
10:46:31  ➤ YN0000: [*********************]: Committed_AS:   19756756 kB
10:46:31  ➤ YN0000: [*********************]: VmallocTotal:   34359738367 kB
10:46:31  ➤ YN0000: [*********************]: VmallocUsed:           0 kB
10:46:31  ➤ YN0000: [*********************]: VmallocChunk:          0 kB
10:46:31  ➤ YN0000: [*********************]: HardwareCorrupted:     0 kB
10:46:31  ➤ YN0000: [*********************]: AnonHugePages:         0 kB
10:46:31  ➤ YN0000: [*********************]: ShmemHugePages:        0 kB
10:46:31  ➤ YN0000: [*********************]: ShmemPmdMapped:        0 kB
10:46:31  ➤ YN0000: [*********************]: HugePages_Total:       0
10:46:31  ➤ YN0000: [*********************]: HugePages_Free:        0
10:46:31  ➤ YN0000: [*********************]: HugePages_Rsvd:        0
10:46:31  ➤ YN0000: [*********************]: HugePages_Surp:        0
10:46:31  ➤ YN0000: [*********************]: Hugepagesize:       2048 kB
10:46:31  ➤ YN0000: [*********************]: DirectMap4k:      563108 kB
10:46:31  ➤ YN0000: [*********************]: DirectMap2M:    15732736 kB
10:46:31  ➤ YN0000: [*********************]: DirectMap1G:           0 kB
10:46:31  ➤ YN0000: [*********************]: Process exited (exit code 0), completed in 10s 351ms
10:46:31  ➤ YN0000: [*********************]: Process started
10:46:31  ➤ YN0000: [*********************]: Internal Error: spawn ENOMEM
10:46:31  ➤ YN0000: [*********************]:     at ChildProcess.spawn (internal/child_process.js:403:11)
10:46:31  ➤ YN0000: [*********************]:     at spawn (child_process.js:667:9)
10:46:31  ➤ YN0000: [*********************] (child_process.js:871:17)
10:46:31  ➤ YN0000: [*********************]:     at FN (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:4:7428)
10:46:31  ➤ YN0000: [*********************]:     at Wf.implementation (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:255:1599)
10:46:31  ➤ YN0000: [*********************]:     at Wf.exec (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:258:1582)
10:46:31  ➤ YN0000: [*********************]:     at Wf.run (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:258:1753)
10:46:31  ➤ YN0000: [*********************]:     at SJ (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:267:6185)
10:46:31  ➤ YN0000: [*********************]:     at async cwe (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:269:16)
10:46:31  ➤ YN0000: [*********************]:     at async o (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:269:146)
10:46:31  ➤ YN0000: [*********************]: Process exited (exit code 1), completed in 0s 725ms
10:46:31  ➤ YN0000: [*********************]: Process started
10:46:32  ➤ YN0000: [*********************]: Internal Error: spawn ENOMEM
10:46:32  ➤ YN0000: [*********************]:     at ChildProcess.spawn (internal/child_process.js:403:11)
10:46:32  ➤ YN0000: [*********************]:     at spawn (child_process.js:667:9)
10:46:32  ➤ YN0000: [*********************] (child_process.js:871:17)
10:46:32  ➤ YN0000: [*********************]:     at FN (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:4:7428)
10:46:32  ➤ YN0000: [*********************]:     at Wf.implementation (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:255:1599)
10:46:32  ➤ YN0000: [*********************]:     at Wf.exec (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:258:1582)
10:46:32  ➤ YN0000: [*********************]:     at Wf.run (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:258:1753)
10:46:32  ➤ YN0000: [*********************]:     at SJ (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:267:6185)
10:46:32  ➤ YN0000: [*********************]:     at async cwe (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:269:16)
10:46:32  ➤ YN0000: [*********************]:     at async o (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:269:146)
10:46:32  ➤ YN0000: [*********************]: Process exited (exit code 1), completed in 0s 803ms
10:46:32  ➤ YN0000: [*********************]: Process started
10:46:33  ➤ YN0000: [*********************]: Internal Error: spawn ENOMEM
10:46:33  ➤ YN0000: [*********************]:     at ChildProcess.spawn (internal/child_process.js:403:11)
10:46:33  ➤ YN0000: [*********************]:     at spawn (child_process.js:667:9)
10:46:33  ➤ YN0000: [*********************] (child_process.js:871:17)
10:46:33  ➤ YN0000: [*********************]:     at FN (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:4:7428)
10:46:33  ➤ YN0000: [*********************]:     at Wf.implementation (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:255:1599)
10:46:33  ➤ YN0000: [*********************]:     at Wf.exec (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:258:1582)
10:46:33  ➤ YN0000: [*********************]:     at Wf.run (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:258:1753)
10:46:33  ➤ YN0000: [*********************]:     at SJ (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:267:6185)
10:46:33  ➤ YN0000: [*********************]:     at async cwe (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:269:16)
10:46:33  ➤ YN0000: [*********************]:     at async o (/opt/jenkins/workspace/*********************_PR-1808/.yarn/releases/yarn-3.0.0.cjs:269:146)
10:46:33  ➤ YN0000: [*********************]: Process exited (exit code 1), completed in 0s 707ms
10:46:41  ➤ YN0000: [*********************] Webpack: Compiled successfully in 17.77s
10:46:41  ➤ YN0000: [*********************]: MemTotal:       15949392 kB
10:46:41  ➤ YN0000: [*********************]: MemFree:         4412368 kB
10:46:41  ➤ YN0000: [*********************]: MemAvailable:   11063020 kB
10:46:41  ➤ YN0000: [*********************]: Buffers:            2704 kB
10:46:41  ➤ YN0000: [*********************]: Cached:          6054880 kB
10:46:41  ➤ YN0000: [*********************]: SwapCached:            0 kB
10:46:41  ➤ YN0000: [*********************]: Active:          4810036 kB
10:46:41  ➤ YN0000: [*********************]: Inactive:        4549224 kB
10:46:41  ➤ YN0000: [*********************]: Active(anon):    3271144 kB
10:46:41  ➤ YN0000: [*********************]: Inactive(anon):      316 kB
10:46:41  ➤ YN0000: [*********************]: Active(file):    1538892 kB
10:46:41  ➤ YN0000: [*********************]: Inactive(file):  4548908 kB
10:46:41  ➤ YN0000: [*********************]: Unevictable:           0 kB
10:46:41  ➤ YN0000: [*********************]: Mlocked:               0 kB
10:46:41  ➤ YN0000: [*********************]: SwapTotal:             0 kB
10:46:41  ➤ YN0000: [*********************]: SwapFree:              0 kB
10:46:41  ➤ YN0000: [*********************]: Dirty:              8500 kB
10:46:41  ➤ YN0000: [*********************]: Writeback:             0 kB
10:46:41  ➤ YN0000: [*********************]: AnonPages:       3301720 kB
10:46:41  ➤ YN0000: [*********************]: Mapped:           171228 kB
10:46:41  ➤ YN0000: [*********************]: Shmem:               560 kB
10:46:41  ➤ YN0000: [*********************]: Slab:            1514824 kB
10:46:41  ➤ YN0000: [*********************]: SReclaimable:     897940 kB
10:46:41  ➤ YN0000: [*********************]: SUnreclaim:       616884 kB
10:46:41  ➤ YN0000: [*********************]: KernelStack:        6896 kB
10:46:41  ➤ YN0000: [*********************]: PageTables:        47072 kB
10:46:41  ➤ YN0000: [*********************]: NFS_Unstable:          0 kB
10:46:41  ➤ YN0000: [*********************]: Bounce:                0 kB
10:46:41  ➤ YN0000: [*********************]: WritebackTmp:          0 kB
10:46:41  ➤ YN0000: [*********************]: CommitLimit:     7974696 kB
10:46:41  ➤ YN0000: [*********************]: Committed_AS:   18929036 kB
10:46:41  ➤ YN0000: [*********************]: VmallocTotal:   34359738367 kB
10:46:41  ➤ YN0000: [*********************]: VmallocUsed:           0 kB
10:46:41  ➤ YN0000: [*********************]: VmallocChunk:          0 kB
10:46:41  ➤ YN0000: [*********************]: HardwareCorrupted:     0 kB
10:46:41  ➤ YN0000: [*********************]: AnonHugePages:         0 kB
10:46:41  ➤ YN0000: [*********************]: ShmemHugePages:        0 kB
10:46:41  ➤ YN0000: [*********************]: ShmemPmdMapped:        0 kB
10:46:41  ➤ YN0000: [*********************]: HugePages_Total:       0
10:46:41  ➤ YN0000: [*********************]: HugePages_Free:        0
10:46:41  ➤ YN0000: [*********************]: HugePages_Rsvd:        0
10:46:41  ➤ YN0000: [*********************]: HugePages_Surp:        0
10:46:41  ➤ YN0000: [*********************]: Hugepagesize:       2048 kB
10:46:41  ➤ YN0000: [*********************]: DirectMap4k:      563108 kB
10:46:41  ➤ YN0000: [*********************]: DirectMap2M:    15732736 kB
10:46:41  ➤ YN0000: [*********************]: DirectMap1G:           0 kB
10:46:41  ➤ YN0000: [*********************]: Process exited (exit code 0), completed in 24s 336ms
@LaurensUP LaurensUP added the bug Something isn't working label Sep 6, 2021
@merceyz merceyz added the upholded Real issues without formal reproduction label Sep 7, 2021
@LaurensUP
Copy link
Author

Working on a reproduce case.

@LaurensUP
Copy link
Author

LaurensUP commented Sep 9, 2021

@arcanis Could this have to do with how Clipanion spawns new processes?
In our former script (that did virtually the same thing as yarn workspaces foreach) we used node's child_process.exec to spawn the commands. This was giving is no memory issues on the same CI machine.

Edit: Using Lerna for these scripts also did not grant the memory issues. I did not check yet how Lerna spawns processes.

@arcanis
Copy link
Member

arcanis commented Sep 9, 2021

The scripts are executed within the same process (here) - it's possible there's a weird interaction somewhere, but my assumption was that in-process execution would be lighter than spawning subprocesses 🤔

@merceyz
Copy link
Member

merceyz commented Sep 9, 2021

It seems to me that there is some kind of memory leak when using yarn workspaces foreach on a big monorepo (~80+ packages).

I tested on a project with 277 workspaces with a total of 6449 packages and it sits at about 400MB memory and doesn't climb so the project size doesn't seem to be the problem

@LaurensUP
Copy link
Author

LaurensUP commented Sep 9, 2021

Our situation is: CI Host > Spawning Docker container > Running yarn commands

We've found a resolution for this by running the following command in the Host
sudo echo 1 > /proc/sys/vm/overcommit_memory

Inspiration came from nodejs/node#25382 (comment)
referencing libuv/libuv#2133

Edit:
This is just another hunch, but we believe it has to do with a combination of workspaces foreach and us using shared scripts.
When we declare a top level command "g:jest": "cd $INIT_CWD && jest" and then call g:jest with workspaces foreach, not only will there be a process spawned for every workspace for g:jest, but it will spawn another process jest. And then jest of course spawns more processes to run the tests.

If all of these child processes allocate the same amount of memory as their parent process, we get the OOM error, even though there is still plenty of memory to go around. The child processes are forked on Linux and claim they "might use" as much memory as the parent, so this amount is allocated.

Now, this has to do with how node.js forks processes on Linux and maybe not so much with yarn, but I would argue that the issue is still valid, as spawning processes with alternatives (custom JS script or Lerna) does not make the same CI system go OOM.

@seansfkelley
Copy link
Contributor

I've been tooling around with replacing Lerna with workspaces foreach recently, and while my memory issues aren't as severe as yours, I have also seen the problem with spawning lots of intermediate processes that do barely anything sucking up resources.

In an attempt to solve it I've been hacking around with a plugin that hooks into the run lifecycle and attempts to run scripts in-process when it thinks it can be done safely, no configuration required. Feel free to check it out; I'm curious to know if it helps. I don't have any plans to publish it or try to merge it upstream cause it seems so finicky and unstable, but I guess I could put something together if the maintainers are interested. I also have some improvements planned to fix some edge cases it currently doesn't handle well.

https://github.com/seansfkelley/berry/tree/alias-run/packages/plugin-run-inline

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working upholded Real issues without formal reproduction
Projects
None yet
Development

No branches or pull requests

4 participants