http2: fix FileHandle leak in respondWithFile#61707
Open
Han5991 wants to merge 2 commits intonodejs:mainfrom
Open
http2: fix FileHandle leak in respondWithFile#61707Han5991 wants to merge 2 commits intonodejs:mainfrom
Han5991 wants to merge 2 commits intonodejs:mainfrom
Conversation
Collaborator
|
Review requested:
|
Ensure that the file handle is closed if header validation fails in respondWithFile. This prevents ERR_INVALID_STATE errors where a FileHandle object is closed during garbage collection.
4859ad9 to
5c4dd6b
Compare
mcollina
requested changes
Feb 6, 2026
Member
mcollina
left a comment
There was a problem hiding this comment.
Thanks for opening a PR! Can you please add a unit test?
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #61707 +/- ##
=======================================
Coverage 89.75% 89.75%
=======================================
Files 674 674
Lines 204416 204428 +12
Branches 39285 39284 -1
=======================================
+ Hits 183472 183484 +12
- Misses 13227 13241 +14
+ Partials 7717 7703 -14
🚀 New features to boost your workflow:
|
Verifies that the file descriptor is closed when an error occurs during header validation in respondWithFile. Refs: 5c4dd6b
Contributor
Author
|
Thank you for your review. I have added unit tests. |
Collaborator
Contributor
Author
|
I think I got a flaki tI think I got a flaki test. Could you please give me the ci again? Thank you.est. Could you please give me the ci again? Thank you. |
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/http2/core.jsthat causesERR_INVALID_STATEwhen garbage collection occurs.In
processRespondWithFD, ifbuildNgHeaderStringthrows (e.g., due to invalid headers), the code would catch the error and destroy the stream but fail to close the file handle (fd) if it owned it (self.ownsFd). This leaves the file handle open, eventually triggering the GC error.This patch adds a
tryClose(fd)call in the catch block and error handling path to ensure the handle is properly released.References