-
-
Notifications
You must be signed in to change notification settings - Fork 34k
test-runner: fix potential memory leaks #60860
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
base: main
Are you sure you want to change the base?
test-runner: fix potential memory leaks #60860
Conversation
|
Review requested:
|
|
@abhishekSavani do you have proof there ever was a memory leak in the first place? |
here i share two demo files for proof. if you want data let me know. i will happy to share. thanks for your comment ref
demo-readline-leak.js Production impact: Real CI/CD systems experiencing OOM crashes
|
|
The two files you posted have nothing to do with changes in this PR. |
|
Also the added tests do not pass, and it's not obvious they even related to the PR |
I noticed the two potential memory leaks while reviewing the Pr ... specifically, the readline.Interface not being closed and the watch mode listener not being removed. I thought to address them for completeness, but please feel free to close this PR if you feel it’s unnecessary. and those two files are just simple scenario replications created by AI, and that it’s difficult to reproduce these issues in actual production environments. |
|
That looks much better, thanks. If you could add a test that fails on |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #60860 +/- ##
==========================================
- Coverage 88.56% 88.56% -0.01%
==========================================
Files 703 703
Lines 208259 208277 +18
Branches 40187 40170 -17
==========================================
+ Hits 184454 184455 +1
- Misses 15812 15827 +15
- Partials 7993 7995 +2
🚀 New features to boost your workflow:
|
- Close readline interface after child process exits Prevents accumulation of event listeners on stderr stream - Extract watch mode event handler to named function Allows proper cleanup when watch mode is aborted These changes prevent unbounded memory growth in long-running test suites and watch mode sessions.
2fc3efb to
6d5c9d1
Compare
i added regression test for memory leaks in test runner |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is passing on main, it's at best unrelated to this PR, please remove it
mcollina
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
This pull request focuses on fixing resource leaks in the test runner, specifically targeting memory leaks caused by unclosed readline interfaces and unreleased event listeners in watch mode. It also introduces new tests to verify that these leaks are resolved and that resources are properly cleaned up across various test scenarios.
Resource management improvements:
runTestFileto prevent memory leaks after test execution.watchFilesto use a named event handler and add a cleanup function that removes the 'changed' event listener, ensuring listeners do not accumulate and are properly released. [1] [2]✅ Prevent memory leaks in test runner process isolation mode
✅ Prevent listener accumulation in watch mode
✅ Improve long-running test suite stability
✅ Reduce memory consumption in CI/CD environments
Why this matters:
ISSUE 1
Without fix: readline.Interface stays open when child writes to stderr -> process might hang indefinitely
With fix: rl.close() is called -> process exits cleanly
Test catches regression: If someone removes rl.close(), test will timeout and fail
ISSUE 2
Without fix: Anonymous listener can't be removed -> watch mode might not exit cleanly on SIGTERM
With fix: Named function with cleanup -> proper shutdown
Test catches regression: If cleanup is removed, watch mode won't exit on SIGTERM, test will timeout