Skip to content

Conversation

@garyking
Copy link
Contributor

@garyking garyking commented Nov 25, 2025

Here are some changes made, using GPT-5, which fixed the issue in #406 for me.

Specifically, it appears to be this line that fixes the issue for me.

@scottlovegrove
Copy link
Contributor

@garyking These changes make sense, thanks for opening the PR.

There are some linting issues that just need to be resolved, please see the CI failure to see what those are.

@scottlovegrove scottlovegrove changed the title Fix script hanging for 30 seconds fix: Fix script hanging for 30 seconds Nov 26, 2025
@garyking
Copy link
Contributor Author

@scottlovegrove Okay, done.

@scottlovegrove scottlovegrove merged commit afd7094 into Doist:main Nov 26, 2025
2 checks passed
scottlovegrove added a commit to Doist/twist-sdk-typescript that referenced this pull request Nov 27, 2025
Fixes connection hang issue similar to todoist-api-typescript#406 where
processes would hang for ~30 seconds after API calls complete when using
Node.js native fetch.

## Root Cause

Node.js native fetch uses undici with ~30s keepAlive timeout by default.
Additionally, the configured timeout (30s) was never actually applied to
fetch calls, and timeout handlers weren't being cleared properly.

## Changes

- **Add undici Agent**: Configure HTTP agent with 1ms keepAlive timeout
  and pass via dispatcher option to prevent connection hangs
- **Fix timeout bug**: Actually apply the configured 30s timeout to fetch calls
- **Add timeout cleanup**: Implement proper clearTimeout functionality to
  prevent hanging timeout handlers
- **Maintain compatibility**: CustomFetch implementations unaffected,
  no breaking changes to public API

## Dependencies

- Added undici ^7.16.0 for connection management

## Testing

- All existing tests pass (166/166)
- Connection hang test confirms ~2s execution vs ~31s before fix
- Timeout enforcement now works correctly

Addresses same issues as:
- Doist/todoist-api-typescript#408
- Doist/todoist-api-typescript#414

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
scottlovegrove added a commit to Doist/twist-sdk-typescript that referenced this pull request Nov 27, 2025
Fixes connection hang issue similar to todoist-api-typescript#406 where
processes would hang for ~30 seconds after API calls complete when using
Node.js native fetch.

## Root Cause

Node.js native fetch uses undici with ~30s keepAlive timeout by default.
Additionally, the configured timeout (30s) was never actually applied to
fetch calls, and timeout handlers weren't being cleared properly.

## Changes

- **Add undici Agent**: Configure HTTP agent with 1ms keepAlive timeout
  and pass via dispatcher option to prevent connection hangs
- **Fix timeout bug**: Actually apply the configured 30s timeout to fetch calls
- **Add timeout cleanup**: Implement proper clearTimeout functionality to
  prevent hanging timeout handlers
- **Maintain compatibility**: CustomFetch implementations unaffected,
  no breaking changes to public API

## Dependencies

- Added undici ^7.16.0 for connection management

## Testing

- All existing tests pass (166/166)
- Connection hang test confirms ~2s execution vs ~31s before fix
- Timeout enforcement now works correctly

Addresses same issues as:
- Doist/todoist-api-typescript#408
- Doist/todoist-api-typescript#414

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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.

2 participants