Skip to content

http: refactor headersTimeout and requestTimeout logic

Fixes: https://github.com/nodejs/node/issues/33440

This PR completely refactors the timeout handling of http.Server as follow:

  1. The server maintains a list of connections, backed by a std::set wrapper in the C++ layer.
  2. The server starts a new interval that every connectionsCheckingInterval milliseconds (a new option in the http.createServer) checks if there any connection for which headersTimeout or requestTimeout has gone off. If that's the case, a timeout event is thrown. The default handler for this event is to respond to the client with status code 408 and then close the connection. This also unifies the behavior for both timeouts.
  3. headersTimeout, requestTimeout and keepAliveTimeout are now supported directly in http.createServer function and they are sanitized.
  4. Default for headersTimeout is now 60 seconds, default for requestTimeout is now 5 minutes.

The use of the interval is needed for performance reason in order to check for the timeouts even if no data is received (as it is at the moment) and this fixes #33440 (closed).

The use of a connection list also constitutes a preparatory work for #41578 (closed).

Merge request reports

Loading