From 4e8f11dee3b7dcea7472058f4182ddd36b86c781 Mon Sep 17 00:00:00 2001 From: Artur K Date: Sat, 11 Sep 2021 14:55:09 +0300 Subject: [PATCH] http: limit requests per connection Fixes: https://github.com/nodejs/node/issues/40071 PR-URL: https://github.com/nodejs/node/pull/40082 Reviewed-By: Matteo Collina Reviewed-By: Robert Nagy --- doc/api/http.md | 16 +++ lib/_http_outgoing.js | 5 +- lib/_http_server.js | 51 +++++--- .../test-http-keep-alive-max-requests.js | 116 ++++++++++++++++++ ...t-http-keep-alive-pipeline-max-requests.js | 86 +++++++++++++ 5 files changed, 258 insertions(+), 16 deletions(-) create mode 100644 test/parallel/test-http-keep-alive-max-requests.js create mode 100644 test/parallel/test-http-keep-alive-pipeline-max-requests.js diff --git a/doc/api/http.md b/doc/api/http.md index 65f2ca3d7184b4..0f5f5a8bb1145d 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -1352,6 +1352,22 @@ By default, the Server does not timeout sockets. However, if a callback is assigned to the Server's `'timeout'` event, timeouts must be handled explicitly. +### `server.maxRequestsPerSocket` + + +* {number} Requests per socket. **Default:** null (no limit) + +The maximum number of requests socket can handle +before closing keep alive connection. + +A value of `null` will disable the limit. + +When limit is reach it will set `Connection` header value to `closed`, +but will not actually close the connection, subsequent requests sent +after the limit is reached will get `503 Service Unavailable` as a response. + ### `server.timeout`