Skip to content

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

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

araujogui wants to merge 4 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 95.45455% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.58%. Comparing base (d3f8545) to head (47dc92e).
⚠️ Report is 90 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/http/server.js 95.23% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67851      +/-   ##
==========================================
+ Coverage   90.53%   90.58%   +0.04%     
==========================================
  Files         805      802       -3     
  Lines      285842   286792     +950     
  Branches    55187    55407     +220     
==========================================
+ Hits       258793   259786     +993     
+ Misses      17167    17099      -68     
- Partials     9882     9907      +25     
Files with missing lines Coverage Δ
lib/https.js 97.25% <100.00%> (-0.01%) ⬇️
lib/internal/http/server.js 96.70% <95.23%> (+0.04%) ⬆️

... and 85 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

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

Copy link
Copy Markdown
Member Author

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

I made the earliest timeout win, so your example closes at 200ms. Added a test and a line in the docs.

Ethan-Arrowood added a commit to Ethan-Arrowood/agentic that referenced this pull request Dec 2, 2026
In the slot run for nodejs/node#67851, the session couldn't write its
probe to the slot's .claude/tmp/, though its allow rule covers the
whole checkout. In dontAsk mode, Claude Code refuses writes under any
.claude/ directory. A headless run confirmed it: the same write to a
folder beside it worked.

slot acquire now creates .review-tmp/ in the slot and adds it to the
clone's info/exclude, which its worktrees share, so the folder never
makes a slot dirty. The run recipes and the session rules use it. The
copied-test recipe's require rewrite changes to ../test/ to match the
new depth.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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.

nice work!

@Ethan-Arrowood Ethan-Arrowood added request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. author ready PRs with CI started, the required approvals, and no outstanding review comments. commit-queue-squash PRs the Commit Queue should land as one squashed commit. labels Dec 2, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Dec 2, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Ethan-Arrowood added a commit to Ethan-Arrowood/agentic that referenced this pull request Dec 2, 2026
In the slot run for nodejs/node#67851, the session couldn't write its
probe to the slot's .claude/tmp/, though its allow rule covers the
whole checkout. In dontAsk mode, Claude Code refuses writes under any
.claude/ directory. A headless run confirmed it: the same write to a
folder beside it worked.

slot acquire now creates .review-tmp/ in the slot and adds it to the
clone's info/exclude, which its worktrees share, so the folder never
makes a slot dirty. The run recipes and the session rules use it. The
copied-test recipe's require rewrite changes to ../test/ to match the
new depth.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. commit-queue-squash PRs the Commit Queue should land as one squashed commit. 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