René's URL Explorer Experiment


Title: http: close pre-request sockets in closeIdleConnections by semimikoh · Pull Request #63470 · nodejs/node · GitHub

Open Graph Title: http: close pre-request sockets in closeIdleConnections by semimikoh · Pull Request #63470 · nodejs/node

X Title: http: close pre-request sockets in closeIdleConnections by semimikoh · Pull Request #63470 · nodejs/node

Description: Problem server.closeIdleConnections() does not close TCP connections that have been accepted but have not yet sent any HTTP data, contradicting its documented behavior ("Closes all connections connected to this server which are not sending a request or waiting for a response") and blocking graceful shutdown when peers (e.g. browsers opening speculative connections) hold sockets open without writing. Repro: import { createServer } from 'node:http'; import { createConnection } from 'node:net'; const server = createServer((req, res) => res.end('ok')); server.listen(3099, '127.0.0.1'); await new Promise((r) => server.once('listening', r)); const sock = createConnection(3099, '127.0.0.1'); await new Promise((r) => sock.once('connect', r)); await new Promise((r) => server.once('connection', r)); const closed = new Promise((r) => server.close(() => r(performance.now()))); const closeStart = performance.now(); server.closeIdleConnections(); const t = await Promise.race([ closed, new Promise((r) => setTimeout(() => r(null), 2000)), ]); console.log(t === null ? 'still hung after 2s' : `closed in ${t - closeStart}ms`); sock.destroy(); Before: still hung after 2s. After: closes immediately. Reported in #63452. Cause New sockets are pushed into kConnections from connectionListenerInternal via parser.initialize(...), but Parser::Initialize (src/node_http_parser.cc) sets last_message_start_ = uv_hrtime() so that headersTimeout / requestTimeout can begin counting (DoS protection). ConnectionsList::Idle() only returns parsers with last_message_start_ === 0, which becomes true only after on_message_complete resets it. Sockets that were accepted but have not sent any HTTP data are therefore classified as active and skipped by closeIdleConnections(). Fix src/node_http_parser.cc: add a received_data_ flag on Parser. It is reset to false in Parser::Initialize (for server-side parsers that own a ConnectionsList) and set to true in on_message_begin, when llhttp signals the first byte of a new HTTP message. ConnectionsList::Idle() now also returns parsers where received_data_ is still false, so accepted-but-pre-request sockets are reported as idle and closed by server.closeIdleConnections(). Per @pimterry's review suggestion, the fix lives at the parser layer rather than as a JS-side filter, so the semantics of idle() are correct for any current or future caller. received_data_ is not part of ParserComparator's ordering key, so it can be updated in place without pop/push around the std::set. Test Added test/parallel/test-http-server-close-idle-connections-pre-request.js. It opens a TCP connection without sending any data, calls server.close() + server.closeIdleConnections(), and uses an unref'd setTimeout(common.mustNotCall(), 1000) as the safety net: if the fix works the event loop drains and the timer never fires; without the fix the timer fires and the assertion trips. Verification The behavior change was first validated by reproducing the fix's semantics in JS (returning pre-request sockets from idle() equivalent) and running the issue's repro, which closed in ~0.4ms instead of hanging. A full local build of the patched binary was not completed because this machine has Apple clang 16.0.0, while the current tree requires a newer toolchain (V8 fails to compile due to missing std::atomic_ref). The C++ change is small and the semantics are 1:1 with the validated JS-equivalent behavior; CI will confirm. Fixes: #63452

Open Graph Description: Problem server.closeIdleConnections() does not close TCP connections that have been accepted but have not yet sent any HTTP data, contradicting its documented behavior ("Closes all connections...

X Description: Problem server.closeIdleConnections() does not close TCP connections that have been accepted but have not yet sent any HTTP data, contradicting its documented behavior ("Closes all connect...

Opengraph URL: https://github.com/nodejs/node/pull/63470

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/commits/:range(.:format)
route-controllerpull_requests
route-actioncommits
fetch-noncev2:087c0748-f019-443a-ced8-5b58e1736f20
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idD3C2:A957D:4B9B79C:651A401:6A65578C
html-safe-nonce7873211f2933a13d7f8c73918ef58dc738f14e9617826292aeb2e070009ee348
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEM0MyOkE5NTdEOjRCOUI3OUM6NjUxQTQwMTo2QTY1NTc4QyIsInZpc2l0b3JfaWQiOiIzNjg5MDM5Mzk3NjM0MDA0ODc2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac380e96a5c6dc4a2bfbefe6124f263a42a506ecd7ba2f4b157deb78ea402c3883
hovercard-subject-tagpull_request:3720910895
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/commits
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/nodejs/node/pull/63470/commits/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df
twitter:imagehttps://avatars.githubusercontent.com/u/123785695?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/123785695?s=400&v=4
og:image:altProblem server.closeIdleConnections() does not close TCP connections that have been accepted but have not yet sent any HTTP data, contradicting its documented behavior ("Closes all connections...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None52c76df668885aaff23b50bdca1fa1ea44ac9c1553e888ebc70ff1e4daa4625b
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/nodejs/node git https://github.com/nodejs/node.git
octolytics-dimension-user_id9950313
octolytics-dimension-user_loginnodejs
octolytics-dimension-repository_id27193779
octolytics-dimension-repository_nwonodejs/node
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id27193779
octolytics-dimension-repository_network_root_nwonodejs/node
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release309153364422b3c499922d1a2a6404910a58ed8e
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/nodejs/node/pull/63470/commits/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fpull%2F63470%2Fcommits%2F700ffb1ff5d4f936c29d63b55cc2ea19f0f104df
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
Code QualityEnforce quality at mergehttps://github.com/features/code-quality
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fpull%2F63470%2Fcommits%2F700ffb1ff5d4f936c29d63b55cc2ea19f0f104df
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Fcommits&source=header-repo&source_repo=nodejs%2Fnode
Reloadhttps://github.com/nodejs/node/pull/63470/commits/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df
Reloadhttps://github.com/nodejs/node/pull/63470/commits/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df
Reloadhttps://github.com/nodejs/node/pull/63470/commits/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df
Please reload this pagehttps://github.com/nodejs/node/pull/63470/commits/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df
nodejs https://github.com/nodejs
nodehttps://github.com/nodejs/node
Please reload this pagehttps://github.com/nodejs/node/pull/63470/commits/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df
Notifications https://github.com/login?return_to=%2Fnodejs%2Fnode
Fork 36.1k https://github.com/login?return_to=%2Fnodejs%2Fnode
Star 118k https://github.com/login?return_to=%2Fnodejs%2Fnode
Code https://github.com/nodejs/node
Issues 1.3k https://github.com/nodejs/node/issues
Pull requests 1.1k https://github.com/nodejs/node/pulls
Actions https://github.com/nodejs/node/actions
Projects https://github.com/nodejs/node/projects
Security and quality 0 https://github.com/nodejs/node/security
Insights https://github.com/nodejs/node/pulse
Code https://github.com/nodejs/node
Issues https://github.com/nodejs/node/issues
Pull requests https://github.com/nodejs/node/pulls
Actions https://github.com/nodejs/node/actions
Projects https://github.com/nodejs/node/projects
Security and quality https://github.com/nodejs/node/security
Insights https://github.com/nodejs/node/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fnodejs%2Fnode%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fnodejs%2Fnode%2Fissues%2Fnew%2Fchoose
nodejs-github-bothttps://github.com/nodejs-github-bot
nodejs:mainhttps://github.com/nodejs/node/tree/main
semimikoh:http/close-idle-pre-requesthttps://github.com/semimikoh/node/tree/http/close-idle-pre-request
Conversation 15 https://github.com/nodejs/node/pull/63470
Commits 1 https://github.com/nodejs/node/pull/63470/commits
Checks 56 https://github.com/nodejs/node/pull/63470/checks
Files changed https://github.com/nodejs/node/pull/63470/files
Please reload this pagehttps://github.com/nodejs/node/pull/63470/commits/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df
http: close pre-request sockets in closeIdleConnections https://github.com/nodejs/node/pull/63470/commits/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df#top
Show all changes 1 commit https://github.com/nodejs/node/pull/63470/files
700ffb1 http: close pre-request sockets in closeIdleConnections semimikoh May 21, 2026 https://github.com/nodejs/node/pull/63470/commits/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df
Clear filters https://github.com/nodejs/node/pull/63470/commits/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df
Please reload this pagehttps://github.com/nodejs/node/pull/63470/commits/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df
Please reload this pagehttps://github.com/nodejs/node/pull/63470/commits/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df
node_http_parser.cc https://github.com/nodejs/node/pull/63470/commits/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df#diff-bbcf7a115fe4680f3a7c076a487c89bd4ce935e7d2a726cfcb3f69331705e25e
test-http-server-close-idle-connections-pre-request.js https://github.com/nodejs/node/pull/63470/commits/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df#diff-6feafd90fde4cc371242ac093783faa823a1daedd3fa1a81ba06f08017c20549
Please reload this pagehttps://github.com/nodejs/node/pull/63470/commits/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df
https://github.com/semimikoh
semimikohhttps://github.com/nodejs/node/commits?author=semimikoh
src/node_http_parser.cchttps://github.com/nodejs/node/pull/63470/commits/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df#diff-bbcf7a115fe4680f3a7c076a487c89bd4ce935e7d2a726cfcb3f69331705e25e
View file https://github.com/semimikoh/node/blob/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df/src/node_http_parser.cc
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/nodejs/node/pull/63470/commits/{{ revealButtonHref }}
https://github.com/nodejs/node/pull/63470/commits/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df#diff-bbcf7a115fe4680f3a7c076a487c89bd4ce935e7d2a726cfcb3f69331705e25e
https://github.com/nodejs/node/pull/63470/commits/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df#diff-bbcf7a115fe4680f3a7c076a487c89bd4ce935e7d2a726cfcb3f69331705e25e
https://github.com/nodejs/node/pull/63470/commits/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df#diff-bbcf7a115fe4680f3a7c076a487c89bd4ce935e7d2a726cfcb3f69331705e25e
https://github.com/nodejs/node/pull/63470/commits/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df#diff-bbcf7a115fe4680f3a7c076a487c89bd4ce935e7d2a726cfcb3f69331705e25e
https://github.com/nodejs/node/pull/63470/commits/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df#diff-bbcf7a115fe4680f3a7c076a487c89bd4ce935e7d2a726cfcb3f69331705e25e
https://github.com/nodejs/node/pull/63470/commits/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df#diff-bbcf7a115fe4680f3a7c076a487c89bd4ce935e7d2a726cfcb3f69331705e25e
https://github.com/nodejs/node/pull/63470/commits/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df#diff-bbcf7a115fe4680f3a7c076a487c89bd4ce935e7d2a726cfcb3f69331705e25e
https://github.com/nodejs/node/pull/63470/commits/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df#diff-bbcf7a115fe4680f3a7c076a487c89bd4ce935e7d2a726cfcb3f69331705e25e
test/parallel/test-http-server-close-idle-connections-pre-request.jshttps://github.com/nodejs/node/pull/63470/commits/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df#diff-6feafd90fde4cc371242ac093783faa823a1daedd3fa1a81ba06f08017c20549
View file https://github.com/semimikoh/node/blob/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df/test/parallel/test-http-server-close-idle-connections-pre-request.js
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/nodejs/node/pull/63470/commits/{{ revealButtonHref }}
Please reload this pagehttps://github.com/nodejs/node/pull/63470/commits/700ffb1ff5d4f936c29d63b55cc2ea19f0f104df
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.