Skip to content

https: keep session listeners from pinning requests - #67328

Open
orgads wants to merge 1 commit into
nodejs:mainfrom
orgads:https-agent-session-retention
Open

orgads wants to merge 1 commit into
nodejs:mainfrom
orgads:https-agent-session-retention

Conversation

@orgads

@orgads orgads commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

The https Agent's createConnection() adds 'session' and 'close' listeners that live as long as the socket. As closures created in createConnection(), they share its V8 context. That context also holds cb, which the proxy-tunnel path captures, and cb leads to the request that created the socket. So every keep-alive TLS socket kept its first request reachable until the socket closed, along with everything the request's listeners capture.

 createConnection(...args)
   ...
-  socket.on('session', (session) => this._cacheSession(options._agentKey, session))
-  socket.once('close', (err) => { if (err) this._evictSession(options._agentKey) })
+  cacheSessions(this, socket, options._agentKey)   // closures capture only these

How this shows up in an application: a voice server sends TTS requests through a keep-alive https agent, and its response listeners close over the call that made the request. Under steady load the pooled sockets are never idle, so each one held one finished call. That was 259 finished calls at 800 concurrent calls. Plain http doesn't do this.

New test test/parallel/test-https-agent-keepalive-request-collectable.js: after the first request completes and its socket goes back to the free pool, the request must be garbage-collectable.

  • Without the fix, gcUntil fails.
  • With the fix, it passes.
  • The same check over plain http already passes on main.

tools/test.py on parallel/test-{https,tls,http-agent,http2}-*: 628 passed and 4 failed. The same 4 fail on main in my environment (system CA, getaddrinfo ENOTFOUND localhost).

🤖 Generated with Claude Code

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

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

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

codecov Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.67%. Comparing base (bd08ba3) to head (7de74b3).
⚠️ Report is 87 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67328      +/-   ##
==========================================
- Coverage   90.70%   90.67%   -0.04%     
==========================================
  Files         802      799       -3     
  Lines      282290   280259    -2031     
  Branches    54406    54118     -288     
==========================================
- Hits       256052   254112    -1940     
+ Misses      16354    16274      -80     
+ Partials     9884     9873      -11     
Files with missing lines Coverage Δ
lib/https.js 96.94% <100.00%> (+0.04%) ⬆️

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

@pimterry pimterry left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice find! LGTM

@pimterry pimterry added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 12, 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 Nov 12, 2026
@nodejs-github-bot

This comment was marked as outdated.

@gurgunday gurgunday left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@gurgunday gurgunday added the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Nov 12, 2026
@pimterry pimterry added the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Nov 13, 2026
@github-actions github-actions Bot removed the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Nov 13, 2026
@nodejs-github-bot

This comment was marked as outdated.

@orgads
orgads force-pushed the https-agent-session-retention branch from 7d2dce4 to e3d6b4d Compare November 14, 2026 20:46
@orgads

orgads commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

Rebased.

Comment thread lib/https.js Resolved
@gurgunday gurgunday removed the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Nov 15, 2026
@jasnell jasnell added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 16, 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 Nov 16, 2026
@nodejs-github-bot

nodejs-github-bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

createConnection() adds 'session' and 'close' listeners that live as
long as the socket. As closures created in createConnection(), they
share its context, which also holds `cb` for the proxy tunnel path.
That callback leads to the request that created the socket, so every
keep-alive socket kept its first request, and whatever the request's
listeners capture, reachable until the socket closed.

Add the listeners from a separate function, so that they capture only
the agent, the socket and the session key. Plain http is unaffected.

The CONNECT proxy path had the same problem: the 'free' listener on
the tunneled socket was created in establishTunnel(), whose context
holds `afterSocket`. Move it to a separate function as well.

Assisted-by: Claude Code
Signed-off-by: Orgad Shaneh <orgad.shaneh@audiocodes.com>
@orgads
orgads force-pushed the https-agent-session-retention branch from e3d6b4d to 7de74b3 Compare November 16, 2026 08:57
@jasnell jasnell added the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 18, 2026
@nodejs-github-bot nodejs-github-bot added commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. and removed commit-queue PRs queued for automated landing through the Commit Queue. labels Nov 18, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Commit Queue failed

   ⚠  Commits were pushed after the last Full PR CI run:
   ⚠  - https: keep session listeners from pinning requests

The pull request was removed from the Commit Queue and labeled commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. . After resolving the failure, remove that label and add commit-queue PRs queued for automated landing through the Commit Queue. to retry.

Full Commit Queue output
�[36m⠋�[39m Loading data for nodejs/node/pull/67328
�[36m⠋�[39m Loading data for nodejs/node/pull/67328
�[36m⠋�[39m Getting collaborator contacts from README of nodejs/node
�[36m⠋�[39m Getting PR from nodejs/node/pull/67328
�[36m⠋�[39m Getting reviews from nodejs/node/pull/67328
�[36m⠋�[39m Getting comments from nodejs/node/pull/67328
�[36m⠋�[39m Getting commits from nodejs/node/pull/67328
✔  Done loading data for nodejs/node/pull/67328
----------------------------------- PR info ------------------------------------
Title      https: keep session listeners from pinning requests (#67328)
Author     Orgad Shaneh <orgads@gmail.com> (@orgads)
Branch     orgads:https-agent-session-retention -> nodejs:main
Labels     https, needs-ci, commit-queue
Commits    1
 - https: keep session listeners from pinning requests
Committers 1
 - Orgad Shaneh <orgad.shaneh@audiocodes.com>
PR-URL: https://github.com/nodejs/node/pull/67328
Reviewed-By: Tim Perry <pimterry@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: James M Snell <jasnell@gmail.com>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/67328
Reviewed-By: Tim Perry <pimterry@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: James M Snell <jasnell@gmail.com>
--------------------------------------------------------------------------------
   ℹ  This PR was created on Sat, 07 Nov 2026 22:10:11 GMT
   ✔  Approvals: 3
   ✔  - Tim Perry (@pimterry): https://github.com/nodejs/node/pull/67328#pullrequestreview-5881222412
   ✔  - Gürgün Dayıoğlu (@gurgunday): https://github.com/nodejs/node/pull/67328#pullrequestreview-5923227672
   ✔  - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/67328#pullrequestreview-5922166458
   ✔  Last GitHub CI successful
   ℹ  Last Full PR CI on 2026-11-16T00:44:46Z: https://ci.nodejs.org/job/node-test-pull-request/79150/
   ⚠  Commits were pushed after the last Full PR CI run:
   ⚠  - https: keep session listeners from pinning requests
�[36m⠙�[39m Querying data for job/node-test-pull-request/79150/
�[36m⠙�[39m Querying data for job/node-test-pull-request/79150/
�[36m⠙�[39m Querying API for job/node-test-pull-request/79150/
✔  Build data downloaded
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu

View workflow run

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

Labels

commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. https Issues and PRs related to the https subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants