fix: wrap kConnector call in try/catch to prevent client hang#4834
fix: wrap kConnector call in try/catch to prevent client hang#4834veeceey wants to merge 2 commits intonodejs:mainfrom
Conversation
When client[kConnector]() throws synchronously (e.g. from tls.connect with bad cert/key), the error was unhandled and left the client in a bad state where subsequent requests would hang indefinitely. Wrapping the call in try/catch with the same cleanup as the error callback (handleConnectError + kResume) restores proper error recovery. Fixes: nodejs#4697
Manual test resultsTested with the repro from the issue: Before the fix, the second request would hang indefinitely. Now both requests throw the expected TLS error and the client stays in a usable state. Existing test suites pass:
|
|
bumping this one — is there anything on my end that needs updating before review? |
|
gentle ping - would love to get some feedback on this when you get a chance |
metcoder95
left a comment
There was a problem hiding this comment.
can you add some test to cover it
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4834 +/- ##
==========================================
- Coverage 93.19% 92.91% -0.29%
==========================================
Files 109 112 +3
Lines 34228 35643 +1415
==========================================
+ Hits 31900 33116 +1216
- Misses 2328 2527 +199 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Have been unable to upgrade undici because of this and other fixes are piling up... can we please get this merged? |
|
Sure. Can you provide a unit test? |
|
@Uzlopak @metcoder95 yep, I should've added a test from the start — that's on me. I'll put together a unit test that reproduces the hang scenario (bad TLS config causing kConnector to throw, second request hanging). will push it shortly. |
Verify that the client doesn't hang when the connector callback throws synchronously. Tests both the error propagation path and recovery after the connector stops throwing.
|
pushed the tests — two cases covering the sync throw scenario:
both use a custom |
|
How can we retrigger the build? Curious if that was a test timeout or related directly to this change 🤔 @veeceey can you push a no-op commit perhaps? |
When
client[kConnector]()throws synchronously (e.g. fromtls.connectwith a bad cert/key), the error goes unhandled and leaves the client in a bad state where all subsequentclient.request()calls hang indefinitely.This wraps the
client[kConnector](...)invocation in a try/catch that performs the same cleanup as the error callback path — callinghandleConnectErrorandclient[kResume]()— so the client recovers properly and further requests can proceed.Repro from the issue:
Tested locally — both requests now throw the expected error and the client stays usable.
Fixes #4697