Skip to content

http: add timeout option to server.close() - #67851

Open
araujogui wants to merge 3 commits into
nodejs:mainfrom
araujogui:http-server-close-timeout
Open

araujogui wants to merge 3 commits into
nodejs:mainfrom
araujogui:http-server-close-timeout

Conversation

@araujogui

Copy link
Copy Markdown
Member

server.close() waits forever for active connections, so one slow or stuck request keeps the server from closing.

This adds a timeout option, in milliseconds, to close() on http.Server and https.Server. Connections still open when it elapses are destroyed with closeAllConnections().

HTTP/2 servers are not covered.

server.close() waits indefinitely for connections that are sending a
request or waiting for a response, so a single slow or stuck request
keeps the server from closing.

Add an optional `options` argument with a `timeout` in milliseconds to
`http.Server` and `https.Server`. Connections that are still open when
it elapses are destroyed with `closeAllConnections()`.

Assisted-by: Claude
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 28, 2026 16:23
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/crypto
  • @nodejs/http
  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added http Issues and PRs related to the http subsystem. https Issues and PRs related to the https subsystem. needs-ci PRs that need a full CI run. labels Nov 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
@codecov

codecov Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.52542% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.59%. Comparing base (d3f8545) to head (1b1b57b).
⚠️ Report is 45 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/http/server.js 91.07% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67851      +/-   ##
==========================================
+ Coverage   90.53%   90.59%   +0.05%     
==========================================
  Files         805      802       -3     
  Lines      285842   286709     +867     
  Branches    55187    55377     +190     
==========================================
+ Hits       258793   259735     +942     
+ Misses      17167    17083      -84     
- Partials     9882     9891       +9     
Files with missing lines Coverage Δ
lib/https.js 97.25% <100.00%> (-0.01%) ⬇️
lib/internal/http/server.js 96.38% <91.07%> (-0.28%) ⬇️

... and 83 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread lib/internal/http/server.js Resolved
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
@araujogui araujogui added the semver-minor PRs that contain new features and should be released in the next minor version. label Nov 30, 2026

@Ethan-Arrowood Ethan-Arrowood left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in favor of this. FYI it complements #66000 and will probably result in a conflict once that merges. Just something to be aware of.

One thing to consider is what happens when close is called twice with different timeouts?

close({ timeout: 200 });
close({ timeout: 1000 });

Should this close at 200ms or at the updated 1000ms? Or should there be a different behavior?

Lastly, the commit mentions "Claude"; per our guidelines, this should be anonymized: https://github.com/nodejs/node/blob/main/doc/contributing/ai-guidelines.md#naming-ai-tools-in-disclosures

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

http Issues and PRs related to the http subsystem. https Issues and PRs related to the https subsystem. needs-ci PRs that need a full CI run. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants