Skip to content

Commit 5db2538

Browse files
Fix for headersTimeout and requestTimeout timers
This commit includes a fix for handling headersTimeout and requestTimeout that causes unexpected behavior if the http server is started on boot - the connections to the server can be closed immediately with the status HTTP 408 This issue usually happens in IoT or embedded devices where the reference timestamp (returned by uv_hrtime()) is counted since boot and can be smaller than the headersTimeout or the requestTimeout value. Additionally added performance improvement to process the list of connection only if one of the timers should be processed
1 parent 82397c0 commit 5db2538

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/node_http_parser.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,9 +1108,13 @@ void ConnectionsList::Expired(const FunctionCallbackInfo<Value>& args) {
11081108

11091109
const uint64_t now = uv_hrtime();
11101110
const uint64_t headers_deadline =
1111-
headers_timeout > 0 ? now - headers_timeout : 0;
1111+
(headers_timeout > 0 && now > headers_timeout) ? now - headers_timeout : 0;
11121112
const uint64_t request_deadline =
1113-
request_timeout > 0 ? now - request_timeout : 0;
1113+
(request_timeout > 0 && now > request_timeout) ? now - request_timeout : 0;
1114+
1115+
if (headers_deadline == 0 && request_deadline == 0) {
1116+
return args.GetReturnValue().Set(Array::New(isolate, 0));
1117+
}
11141118

11151119
auto iter = list->active_connections_.begin();
11161120
auto end = list->active_connections_.end();

0 commit comments

Comments
 (0)