Skip to content

Conversation

@0saurabh0
Copy link

The withTimeout function creates a timeout promise that rejects after a delay, but the resolve callback is placed on a separate line without being called. This means the timeout is never cleared even when the main promise completes first, this can cause memory leaks and zombie timers.

Fix :

  • Store setTimeout ID and clear it when promise race completes
  • Use .finally() to ensure cleanup in all cases
  • Remove unused resolve reference

const timeout = new Promise((_, reject) => {
timeoutId = setTimeout(() => {
reject(`${id} timed out after ${millis / 1000} s.`);
resolve;
Copy link
Author

Choose a reason for hiding this comment

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

This resolve was not doing anything

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.

1 participant