Skip to content

Commit a259ee4

Browse files
indutnyMyles Borins
authored andcommitted
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 <jasnell@gmail.com>
1 parent 5b42ef5 commit a259ee4

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

‎lib/_http_server.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ function connectionListener(socket) {
364364
}
365365

366366
functiononParserExecute(ret,d){
367+
socket._unrefTimer();
367368
debug('SERVER socketOnParserExecute %d',ret);
368369
onParserExecuteCommon(ret,undefined);
369370
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
3+
constcommon=require('../common');
4+
constassert=require('assert');
5+
consthttp=require('http');
6+
7+
constserver=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+
constreq=http.request({
24+
port: common.PORT,
25+
method: 'POST'
26+
},(res)=>{
27+
constinterval=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)