repl: fix FileHandle leak in history initialization#61706
Open
Han5991 wants to merge 2 commits intonodejs:mainfrom
Open
repl: fix FileHandle leak in history initialization#61706Han5991 wants to merge 2 commits intonodejs:mainfrom
Han5991 wants to merge 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
Member
|
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
Contributor
Author
|
Thank you for your review, I have finished adding unit tests. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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