From 7322e58d118861801530153b2c4dbfc5e83cfac7 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Fri, 31 Jul 2020 14:42:39 +0200 Subject: [PATCH] http: reset headers timeout on headers complete headers timeout should not occur *after* headers have been received. Fixes: https://github.com/nodejs/node/issues/34576 PR-URL: https://github.com/nodejs/node/pull/34578 Reviewed-By: Anna Henningsen Reviewed-By: Fedor Indutny Reviewed-By: Luigi Pinca Reviewed-By: James M Snell Reviewed-By: Pranshu Srivastava --- src/node_http_parser.cc | 1 + .../test-http-parser-timeout-reset.js | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 test/parallel/test-http-parser-timeout-reset.js diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc index c7a3df8d067af4..b409d007307877 100644 --- a/src/node_http_parser.cc +++ b/src/node_http_parser.cc @@ -280,6 +280,7 @@ class Parser : public AsyncWrap, public StreamListener { int on_headers_complete() { header_nread_ = 0; + header_parsing_start_time_ = 0; // Arguments for the on-headers-complete javascript callback. This // list needs to be kept in sync with the actual argument list for diff --git a/test/parallel/test-http-parser-timeout-reset.js b/test/parallel/test-http-parser-timeout-reset.js new file mode 100644 index 00000000000000..c9daa7c2124a73 --- /dev/null +++ b/test/parallel/test-http-parser-timeout-reset.js @@ -0,0 +1,46 @@ +'use strict'; +const common = require('../common'); + +const net = require('net'); +const { HTTPParser } = process.binding('http_parser'); + +const server = net.createServer((socket) => { + socket.write('HTTP/1.1 200 OK\r\n'); + socket.write('Transfer-Encoding: chunked\r\n\r\n'); + setTimeout(() => { + socket.write('1\r\n'); + socket.write('\n\r\n'); + setTimeout(() => { + socket.write('1\r\n'); + socket.write('\n\r\n'); + setImmediate(() => { + socket.destroy(); + server.close(); + }); + }, 500); + }, 500); +}).listen(0, () => { + const socket = net.connect(server.address().port); + const parser = new HTTPParser(HTTPParser.RESPONSE, false); + parser.initialize( + HTTPParser.RESPONSE, + {}, + 0, + false, + 1e3 + ); + + parser[HTTPParser.kOnTimeout] = common.mustNotCall(); + + parser[HTTPParser.kOnHeaders] = common.mustNotCall(); + + parser[HTTPParser.kOnExecute] = common.mustCall(3); + + parser[HTTPParser.kOnHeadersComplete] = common.mustCall(); + + parser[HTTPParser.kOnBody] = common.mustCall(2); + + parser[HTTPParser.kOnMessageComplete] = common.mustNotCall(); + + parser.consume(socket._handle); +});