fix: resolve 30-second connection hang in v6.0.0+ #408
+28
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #406 - Resolves the 30-second connection hang issue that was introduced in PR #377 when the library migrated from axios to Node.js native fetch.
Problem
After any API call completes in versions 6.0.0+, the process hangs for approximately 30 seconds before terminating. This also affects Jest tests, causing them to hang even with mocked requests (nock/msw).
Root Cause
Node.js native
fetchuses undici under the hood with a global HTTP connection pool that keeps connections alive by default. The default keepAlive timeout is ~30 seconds, causing connections to stay open waiting for potential reuse.Solution
Configure undici's HTTP Agent with very short keepAlive timeouts (1ms) and pass it to all native fetch calls via the
dispatcheroption. This ensures connections close immediately after requests complete.Changes
undici(^7.16.0) as a dependencysrc/utils/fetch-with-retry.tsdispatcheroptionTesting
Manual Testing
Test Script for Reviewers
You can verify this fix by running the following test script. Save it as
test-connection-hang.jsand run it withnode test-connection-hang.js <your-api-token>:How to Reproduce the Bug (Optional)
To see the original bug behavior:
Impact
🤖 Generated with Claude Code