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 Apr 16, 2019
1 parent 9f5ad9b commit cb88c58
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
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,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
Original file line number Diff line number Diff line change
@@ -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 cb88c58

Please sign in to comment.