Skip to content

Commit

Permalink
http: check for existance in resetHeadersTimeoutOnReqEnd
Browse files Browse the repository at this point in the history
socket.parser can be undefined under unknown circumstances.
This is a fix for a bug I cannot reproduce but it is affecting
people.

Fixes: #26366

PR-URL: #26402
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
mcollina authored and BethGriggs committed Sep 19, 2019
1 parent 5682e50 commit 1a5dc6a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/_http_server.js
Expand Up @@ -724,7 +724,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();
}
}
Expand Down
24 changes: 24 additions & 0 deletions test/parallel/test-http-server-delete-parser.js
@@ -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();

0 comments on commit 1a5dc6a

Please sign in to comment.