Skip to content

Conversation

@vivganes
Copy link
Contributor

This PR fixes #136

Rootcause

When idlePromise resolved first (successful response), the setTimeout timer kept running in the background. Since Node.js keeps the event loop alive while there are pending timers, the process couldn't exit until the timer fired.

Fix

Store the timer ID and call clearTimeout in the finally block to cancel the timer when done.

@vivganes vivganes requested a review from a team as a code owner January 27, 2026 01:03
Copilot AI review requested due to automatic review settings January 27, 2026 01:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes issue #136 where the Node.js process would hang after client.stop() due to a dangling setTimeout timer in the sendAndWait method. The timer kept the event loop alive even after successful completion, preventing process exit.

Changes:

  • Added timer cleanup in sendAndWait by storing the timeout ID and calling clearTimeout in the finally block
  • Added unit tests to verify the timeout timer is properly cleared in success and error scenarios

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
nodejs/src/session.ts Fixed dangling timer by storing timeout ID and clearing it in the finally block
nodejs/test/session.test.ts Added comprehensive unit tests for timeout cleanup behavior

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

[TypeScript SDK] Process not returning properly after client stop / dangling promise in sendAndWait

2 participants