repl: fix FileHandle leak in history initialization#61706
repl: fix FileHandle leak in history initialization#61706nodejs-github-bot merged 2 commits intonodejs:mainfrom
Conversation
a710016 to
9d08876
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #61706 +/- ##
==========================================
- Coverage 89.76% 89.75% -0.01%
==========================================
Files 674 674
Lines 204424 204425 +1
Branches 39289 39287 -2
==========================================
- Hits 183499 183480 -19
- Misses 13219 13256 +37
+ Partials 7706 7689 -17
🚀 New features to boost your workflow:
|
Ensure that the history file handle is closed if initialization fails or flushing throws an error. This prevents ERR_INVALID_STATE errors where a FileHandle object is closed during garbage collection.
9d08876 to
52e5e2d
Compare
|
Is it possible to add a test? |
This adds a test case to verify that the file handle is properly closed when REPL history initialization fails, preventing resource leaks. Refs: 52e5e2d
|
Thank you for your review, I have finished adding unit tests. |
|
I think a flare test occurred. Could you please request the CI again? Thank you. |
Commit Queue failed- Loading data for nodejs/node/pull/61706 ✔ Done loading data for nodejs/node/pull/61706 ----------------------------------- PR info ------------------------------------ Title repl: fix FileHandle leak in history initialization (#61706) Author sangwook <rewq5991@gmail.com> (@Han5991) Branch Han5991:fix/repl-history-filehandle-leak -> nodejs:main Labels repl, author ready, needs-ci Commits 2 - repl: fix FileHandle leak in history initialization - test: add regression test for repl history leak Committers 1 - sangwook <rewq5991@gmail.com> PR-URL: https://github.com/nodejs/node/pull/61706 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Anna Henningsen <anna@addaleax.net> ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/61706 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Anna Henningsen <anna@addaleax.net> -------------------------------------------------------------------------------- ℹ This PR was created on Fri, 06 Feb 2026 12:58:24 GMT ✔ Approvals: 3 ✔ - Luigi Pinca (@lpinca): https://github.com/nodejs/node/pull/61706#pullrequestreview-3767812467 ✔ - Gürgün Dayıoğlu (@gurgunday): https://github.com/nodejs/node/pull/61706#pullrequestreview-3767899580 ✔ - Anna Henningsen (@addaleax): https://github.com/nodejs/node/pull/61706#pullrequestreview-3772404810 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2026-02-08T16:45:41Z: https://ci.nodejs.org/job/node-test-pull-request/71256/ - Querying data for job/node-test-pull-request/71256/ ✔ Build data downloaded ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ No git cherry-pick in progress ✔ No git am in progress ✔ No git rebase in progress -------------------------------------------------------------------------------- - Bringing origin/main up to date... From https://github.com/nodejs/node * branch main -> FETCH_HEAD ✔ origin/main is now up-to-date - Downloading patch for 61706 From https://github.com/nodejs/node * branch refs/pull/61706/merge -> FETCH_HEAD ✔ Fetched commits as aa3e649ca1ef..e87b6f401794 -------------------------------------------------------------------------------- [main a717e4037d] repl: fix FileHandle leak in history initialization Author: sangwook <rewq5991@gmail.com> Date: Fri Feb 6 21:57:03 2026 +0900 1 file changed, 1 insertion(+) [main 1cd06c80ad] test: add regression test for repl history leak Author: sangwook <rewq5991@gmail.com> Date: Sat Feb 7 06:47:58 2026 +0900 1 file changed, 56 insertions(+) create mode 100644 test/parallel/test-repl-history-init-fail-leak.js ✔ Patches applied There are 2 commits in the PR. Attempting autorebase. (node:664) [DEP0190] DeprecationWarning: Passing args to a child process with shell option true can lead to security vulnerabilities, as the arguments are not escaped, only concatenated. (Use `node --trace-deprecation ...` to show where the warning was created) Rebasing (2/4) Executing: git node land --amend --yes --------------------------------- New Message ---------------------------------- repl: fix FileHandle leak in history initializationhttps://github.com/nodejs/node/actions/runs/21821224872 |
|
Landed in 71b36ee |
Summary
This PR fixes a
FileHandleleak inlib/internal/repl/history.jsthat causesERR_INVALID_STATEwhen garbage collection occurs.If an error occurs during
kInitializeHistory(specifically within thetryblock that includeskFlushHistory), the openFileHandle(this[kHistoryHandle]) was not being explicitly closed before delegating tokHandleHistoryInitError. This led to the handle being closed by the garbage collector, triggering the error.This fixes the regression observed in
test-repl-programmatic-history.References
Fixes #61578