diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 34558ce459e6d6..28acc533410d3f 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -2149,6 +2149,7 @@ function doSendFileFD(session, options, fd, headers, streamOptions, err, stat) { isDirectory) { const err = isDirectory ? new ERR_HTTP2_SEND_FILE() : new ERR_HTTP2_SEND_FILE_NOSEEK(); + tryClose(fd); if (onError) onError(err); else @@ -2179,6 +2180,7 @@ function doSendFileFD(session, options, fd, headers, streamOptions, err, stat) { if ((typeof options.statCheck === 'function' && options.statCheck.call(this, stat, headers) === false) || (this[kState].flags & STREAM_FLAGS_HEADERS_SENT)) { + tryClose(fd); return; }