fix(client): reject pipelined TLS altname errors#5373
Conversation
Drain already running requests before rejecting same-servername pending requests so TLS hostname failures reject the request promises instead of tripping the queue assertion. Fixes nodejs#5355 Signed-off-by: marko1olo <barsukdana@gmail.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5373 +/- ##
==========================================
- Coverage 93.25% 93.24% -0.01%
==========================================
Files 110 110
Lines 36738 36744 +6
==========================================
+ Hits 34259 34262 +3
- Misses 2479 2482 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| if (err.code === 'ERR_TLS_CERT_ALTNAME_INVALID') { | ||
| assert(client[kRunning] === 0) | ||
| const running = client[kQueue].splice(client[kRunningIdx], client[kRunning]) | ||
| client[kPendingIdx] = client[kRunningIdx] |
There was a problem hiding this comment.
makes sense. the original assert(client[kRunning] === 0) assumed no pipelining — splicing out the running requests and rejecting them before handling pending ones is the right approach. using splice for pending too avoids the index shift issue. test with 20 pipelined requests against a bad cert is a good coverage of the race.
|
Good catch — before this fix, running requests with a matching servername would stay in the queue and never get rejected when a TLS altname error hits. Using |
This relates to...
Fixes #5355
Rationale
ERR_TLS_CERT_ALTNAME_INVALIDhad a special connect-error path that assertedclient[kRunning] === 0before rejecting pending requests for the current server name. Withpipelining > 1, requests can already be in the running segment when the TLS hostname validation error is reported, so the assertion can crash the process instead of rejecting the affected request promises.Changes
Features
N/A
Bug Fixes
Breaking Changes and Deprecations
N/A
Status
Tested
node --test test\node-test\client-tls.jsNODE_OPTIONS=--expose-gc node --test test\tls-cert-leak.jsnode --test test\client-connect.jsnode --test --test-name-pattern servername test\node-test\client-dispatch.jseslint lib\dispatcher\client.js test\node-test\client-tls.jsgit diff --check