Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -2680,6 +2680,8 @@ function processRespondWithFD(self, fd, headers, offset = 0, length = -1,
try {
headersList = buildNgHeaderString(headers, assertValidPseudoHeaderResponse);
} catch (err) {
if (self.ownsFd)
tryClose(fd);
self.destroy(err);
return;
}
Expand All @@ -2693,6 +2695,8 @@ function processRespondWithFD(self, fd, headers, offset = 0, length = -1,
const ret = self[kHandle].respond(headersList, streamOptions);

if (ret < 0) {
if (self.ownsFd)
tryClose(fd);
self.destroy(new NghttpError(ret));
return;
}
Expand Down
51 changes: 51 additions & 0 deletions test/parallel/test-http2-respond-file-fd-leak.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const fixtures = require('../common/fixtures');
const assert = require('assert');
const http2 = require('http2');
const fs = require('fs');

const fname = fixtures.path('elipses.txt');

const server = http2.createServer();

server.on('stream', common.mustCall((stream) => {
const originalClose = fs.close;
let fdClosed = false;

fs.close = common.mustCall(function(fd, cb) {
fdClosed = true;
return originalClose.apply(this, arguments);
});

const headers = {
':method': 'GET',
'content-type': 'text/plain'
};

stream.respondWithFile(fname, headers);

stream.on('error', common.mustCall((err) => {
assert.strictEqual(err.code, 'ERR_HTTP2_INVALID_PSEUDOHEADER');
}));

stream.on('close', common.mustCall(() => {
fs.close = originalClose;
assert.strictEqual(fdClosed, true);
}));
}));

server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
const req = client.request();

req.on('close', common.mustCall(() => {
client.close();
server.close();
}));

req.on('error', common.mustCall());
req.end();
}));
Loading