From edbaebf01acade362e28b169c8daf81504a06ff1 Mon Sep 17 00:00:00 2001 From: WhatCats Date: Fri, 18 Sep 2026 21:21:00 +0200 Subject: [PATCH] http: close busy connections after server.close() `server.close()` only closes connections that are idle at that moment. A busy one stays keep-alive after its response, serving requests until `keepAliveTimeout` reaps it. This is a breaking change: such a connection now closes once it has answered every request it accepted. Its last response says `Connection: close`, unless its headers were written before close(). A request that arrives behind a pending response after close() is not processed. Connections accepted after close(), e.g. once the server listens again, are not affected. Four existing tests called close() while their connection was still in use. They now expect `Connection: close`, or call close() only once they are done with the connection. Signed-off-by: WhatCats Assisted-by: a closed-source coding agent --- doc/api/http.md | 12 +- lib/internal/http/server.js | 43 +- ...est-http-pipeline-assertionerror-finish.js | 9 +- ...t-http-pipeline-socket-parser-typeerror.js | 7 +- test/parallel/test-http-raw-headers.js | 4 +- .../test-http-server-close-when-idle.js | 448 ++++++++++++++++++ test/parallel/test-http-server-unconsume.js | 3 +- 7 files changed, 514 insertions(+), 12 deletions(-) create mode 100644 test/parallel/test-http-server-close-when-idle.js diff --git a/doc/api/http.md b/doc/api/http.md index af939001c9e5..ecbccda99306 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -1759,6 +1759,11 @@ unless the user specified another socket type.