From 3c83f934378ca1af517cbf35981e59ede877c0ec Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Sat, 2 Mar 2019 19:09:44 +0100 Subject: [PATCH] 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 Reviewed-By: Colin Ihrig --- lib/_http_server.js | 2 +- .../test-http-server-delete-parser.js | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-http-server-delete-parser.js diff --git a/lib/_http_server.js b/lib/_http_server.js index 02cd7a81a9cc0b..53bf30b3d240a3 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -755,7 +755,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(); } } diff --git a/test/parallel/test-http-server-delete-parser.js b/test/parallel/test-http-server-delete-parser.js new file mode 100644 index 00000000000000..0c5eea90734170 --- /dev/null +++ b/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();