Skip to content

fix: do not send a request on a connection verified for another servername - #6233

Merged
mcollina merged 1 commit into
mainfrom
fix/servername-switch-while-connecting
Nov 20, 2026
Merged

mcollina merged 1 commit into
mainfrom
fix/servername-switch-while-connecting

Conversation

@mcollina

Copy link
Copy Markdown
Member

Since #6219, a request aborted while it waits for a connection leaves the queue. When a Client serves several TLS server names, as with interceptors.dns() or a per-request servername, and the aborted request was the last one for the name being connected, _resume() switched to the next request's servername while the connection was still pending. Once connected, that connection, whose certificate was verified for the previous name, was used for the next request. This is a regression in 8.13.0.

A connection attempt now records the servername it verifies and is discarded if the Client switched to another name by the time it connects. When _resume() switches names, it also cancels the pending attempt, so the next request does not wait for a connection it cannot use. A certificate name error now fails only the requests for the name it was raised for.

test/servername-switch-while-connecting.js covers h1, h2, an Agent with the dns interceptor, and a custom connector that cannot be cancelled.

Reported privately by @w116tjb.

…rname

Since #6219, a request aborted while it waits for a connection leaves the
queue. When a Client serves several TLS server names and the aborted
request was the last one for the name it was connecting for, _resume()
switched client[kServerName] to the next queued request's name while the
connection was pending. Once connected, that connection, whose certificate
was verified for the previous name, was used for the next request.

A connection attempt now records the servername it verifies. If the
Client switched to another name by the time it connects, the socket is
destroyed and a new connection is opened for the current name. When
_resume() switches the name, it also cancels the pending attempt, so the
request does not wait for a connection it cannot use. A certificate name
error now only fails the requests for the name it was raised for.

Refs: #6219
Signed-off-by: Matteo Collina <hello@matteocollina.com>
@codecov-commenter

codecov-commenter commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.72%. Comparing base (670d0b6) to head (6c11ffa).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6233   +/-   ##
=======================================
  Coverage   91.71%   91.72%           
=======================================
  Files         113      113           
  Lines       44813    44835   +22     
=======================================
+ Hits        41102    41124   +22     
  Misses       3711     3711           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

@mcollina
mcollina merged commit 6b22aba into main Nov 20, 2026
38 checks passed
@mcollina
mcollina deleted the fix/servername-switch-while-connecting branch November 20, 2026 17:54
@github-actions github-actions Bot mentioned this pull request Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants