Skip to content

Commit

Permalink
http: fix for handling on boot timers headers and request
Browse files Browse the repository at this point in the history
This change is 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 on 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
  • Loading branch information
franciszek-koltuniuk-red committed Jun 7, 2023
1 parent 82397c0 commit af39202
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/node_http_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1108,9 +1108,13 @@ void ConnectionsList::Expired(const FunctionCallbackInfo<Value>& args) {

const uint64_t now = uv_hrtime();
const uint64_t headers_deadline =
headers_timeout > 0 ? now - headers_timeout : 0;
(headers_timeout > 0 && now > headers_timeout) ? now - headers_timeout : 0;
const uint64_t request_deadline =
request_timeout > 0 ? now - request_timeout : 0;
(request_timeout > 0 && now > request_timeout) ? now - request_timeout : 0;

if (headers_deadline == 0 && request_deadline == 0) {
return args.GetReturnValue().Set(Array::New(isolate, 0));
}

auto iter = list->active_connections_.begin();
auto end = list->active_connections_.end();
Expand Down

0 comments on commit af39202

Please sign in to comment.