Skip to content

Commit 5c4dd6b

Browse files
committed
http2: fix FileHandle leak in respondWithFile
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.
1 parent 413dffc commit 5c4dd6b

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lib/internal/http2/core.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2680,6 +2680,8 @@ function processRespondWithFD(self, fd, headers, offset = 0, length = -1,
26802680
try {
26812681
headersList = buildNgHeaderString(headers, assertValidPseudoHeaderResponse);
26822682
} catch (err) {
2683+
if (self.ownsFd)
2684+
tryClose(fd);
26832685
self.destroy(err);
26842686
return;
26852687
}
@@ -2693,6 +2695,8 @@ function processRespondWithFD(self, fd, headers, offset = 0, length = -1,
26932695
const ret = self[kHandle].respond(headersList, streamOptions);
26942696

26952697
if (ret < 0) {
2698+
if (self.ownsFd)
2699+
tryClose(fd);
26962700
self.destroy(new NghttpError(ret));
26972701
return;
26982702
}

0 commit comments

Comments
 (0)