fix: resolve 30-second connection hang in native fetch #62
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
Resolves the 30-second connection hang issue when using Node.js native fetch, similar to the issue fixed in todoist-api-typescript. After any API call completes, processes would hang for approximately 30 seconds before terminating.
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. Additionally, this SDK had two related issues:Solution
Applied the same fixes as todoist-api-typescript PRs #408 and #414:
dispatcheroptionChanges
undici(^7.16.0) as a dependency for connection managementsrc/rest-client.tsfetchWithRetry()to use the undici agent and apply timeouts correctlyCompatibility
Testing
Automated Tests
Connection Hang Verification
You can verify this fix by running the test script included in this PR:
npm install && npm run build node test-connection-hang-repro.jsExpected Results:
The test script uses a mock token (will fail with auth error) but demonstrates the timing behavior:
Impact
Related Issues
This fix addresses the same connection hang issues that were resolved in the Todoist SDK:
🤖 Generated with Claude Code