Skip to content

Commit ec2822a

Browse files
committed
http: unref socket timer on parser execute
When underlying `net.Socket` instance is consumed in http server - no `data` events are emitted, and thus `socket.setTimeout` fires the callback even if the data is constantly flowing into the socket. Fix this by calling `socket._unrefTimer()` on every `onParserExecute` call. Fix: #5899 PR-URL: #6286 Reviewed-By: James M Snell <[email protected]>
1 parent 75487f0 commit ec2822a

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

lib/_http_server.js

+1
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ function connectionListener(socket) {
365365
}
366366

367367
function onParserExecute(ret, d) {
368+
socket._unrefTimer();
368369
debug('SERVER socketOnParserExecute %d', ret);
369370
onParserExecuteCommon(ret, undefined);
370371
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const http = require('http');
6+
7+
const server = http.createServer((req, res) => {
8+
server.close();
9+
10+
res.writeHead(200);
11+
res.flushHeaders();
12+
13+
req.setTimeout(common.platformTimeout(200), () => {
14+
assert(false, 'Should not happen');
15+
});
16+
req.resume();
17+
req.once('end', common.mustCall(() => {
18+
res.end();
19+
}));
20+
});
21+
22+
server.listen(common.PORT, common.mustCall(() => {
23+
const req = http.request({
24+
port: common.PORT,
25+
method: 'POST'
26+
}, (res) => {
27+
const interval = setInterval(() => {
28+
req.write('a');
29+
}, common.platformTimeout(25));
30+
setTimeout(() => {
31+
clearInterval(interval);
32+
req.end();
33+
}, common.platformTimeout(400));
34+
});
35+
req.write('.');
36+
}));

0 commit comments

Comments
 (0)