http: check for existance in resetHeadersTimeoutOnReqEnd

socket.parser can be undefined under unknown circumstances.
This is a fix for a bug I cannot reproduce but it is affecting
people.

Fixes: https://github.com/nodejs/node/issues/26366

PR-URL: https://github.com/nodejs/node/pull/26402
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
Matteo Collina authored and Ruben Bridgewater committed 2019-03-14 11:02:21 +01:00
1 parent 654f4d4338
commit 4886fbfbee
2 files changed
+25 -1

No files matched your search

+1 -1
View File
@@ -746,7 +746,7 @@ function resetHeadersTimeoutOnReqEnd() {
const parser = this.socket.parser;
// Parser can be null if the socket was destroyed
// in that case, there is nothing to do.
if (parser !== null) {
if (parser) {
parser.parsingHeadersStart = nowDate();
}
}
@@ -0,0 +1,24 @@
'use strict';
const common = require('../common');
const http = require('http');
const server = http.createServer(common.mustCall((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('okay', common.mustCall(() => {
delete res.socket.parser;
}));
res.end();
}));
server.listen(1337, '127.0.0.1');
server.unref();
const req = http.request({
port: 1337,
host: '127.0.0.1',
method: 'GET',
});
req.end();