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:
- The server maintains a list of connections, backed by a
std::set
wrapper in the C++ layer. - The server starts a new interval that every
connectionsCheckingInterval
milliseconds (a new option in thehttp.createServer
) checks if there any connection for whichheadersTimeout
orrequestTimeout
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. -
headersTimeout
,requestTimeout
andkeepAliveTimeout
are now supported directly inhttp.createServer
function and they are sanitized. - Default for
headersTimeout
is now 60 seconds, default forrequestTimeout
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).