diff --git a/lib/_http_server.js b/lib/_http_server.js index 46b786b07c862c..db5d3d306d60a0 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -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(); } } 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();