Skip to content

tls: destroy socket when newSession listener throws - #67605

Open
ShogunPanda wants to merge 1 commit into
nodejs:mainfrom
ShogunPanda:tls-destroy-socket-on-newsession-error
Open

ShogunPanda wants to merge 1 commit into
nodejs:mainfrom
ShogunPanda:tls-destroy-socket-on-newsession-error

Conversation

@ShogunPanda

Copy link
Copy Markdown
Contributor

When a newSession listener on a tls.Server throws, the guard in onnewsession re-emits the exception as an 'error' event on the server instead of destroying the socket, unlike the other handshake callback guards (SNICallback, resumeSession, OCSPRequest). A server without an 'error' listener then rethrows it from inside the callback.

The exception is now routed to socket.destroy(err). The regression test no longer registers a server 'error' listener, and checks that the server-side socket is destroyed with the original error.

AI-assisted work. All changes reviewed by a human.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/crypto
  • @nodejs/net

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

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.58%. Comparing base (cdd0687) to head (ab9ef87).
⚠️ Report is 351 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67605      +/-   ##
==========================================
- Coverage   90.73%   90.58%   -0.15%     
==========================================
  Files         801      802       +1     
  Lines      280794   286935    +6141     
  Branches    54202    55408    +1206     
==========================================
+ Hits       254771   259915    +5144     
- Misses      16202    17116     +914     
- Partials     9821     9904      +83     
Files with missing lines Coverage Δ
lib/internal/tls/wrap.js 95.80% <100.00%> (ø)

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

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

lgtm. pls fix commit lint error

Route exceptions thrown by `newSession` listeners to
`socket.destroy(err)`, like the other handshake callback guards,
instead of re-emitting them on the server. Update the regression test
to run without a server `error` listener.

Assisted-By: OpenAI GPT-5.6 Sol <openai/gpt-5.6-sol>
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
@ShogunPanda
ShogunPanda force-pushed the tls-destroy-socket-on-newsession-error branch from 5584c8d to ab9ef87 Compare December 3, 2026 08:02
@ShogunPanda ShogunPanda 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 Dec 3, 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 3, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

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

Labels

needs-ci PRs that need a full CI run. tls Issues and PRs related to the tls subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants