Closed
Description
openedon Jul 2, 2021
Parent process continuously grow memory usage while executing multiple child worker processes that return large chunks of data.
I prepared sample repository to reproduce issue: https://github.com/IIIEII/jest-worker-farm-leak
It has worker that returns large array with strings.
Parent process executes it three times with pause of 10s between.
Steps:
- Run sample script in inspect mode
node --inspect --expose-gc src/parent.js
- Connect with chrome inspector and record allocation timeline
It seems that problem lies here: https://github.com/facebook/jest/blob/7a64ede2163eba4ecc725f448cd92102cd8c14aa/packages/jest-worker/src/Farm.ts#L136-L138
Possible solution:
- Make change to
node_modules/jest-worker/build/Farm.js
file:
Index: node_modules/jest-worker/build/Farm.js
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/node_modules/jest-worker/build/Farm.js b/node_modules/jest-worker/build/Farm.js
--- a/node_modules/jest-worker/build/Farm.js (date 1625231320301)
+++ b/node_modules/jest-worker/build/Farm.js (date 1625231320301)
@@ -140,10 +140,11 @@
// and other properties of the task object, such as task.request can be
// garbage collected.
- const taskOnEnd = task.onEnd;
+ let taskOnEnd = task.onEnd;
const onEnd = (error, result) => {
taskOnEnd(error, result);
+ taskOnEnd = null;
this._unlock(workerId);
- Run sample script in inspect mode
node --inspect --expose-gc src/parent.js
- Connect with chrome inspector and record allocation timeline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Metadata
Assignees
Labels
No labels