fix: remove stale waiter in waitForState timeout handler#330
Open
YunchuWang wants to merge 1 commit into
Open
Conversation
The timeout handler in InMemoryOrchestrationBackend.waitForState() used findIndex with `w.resolve === resolve` to locate and remove the timed-out waiter. However, the waiter's resolve property is a wrapper function that calls clearTimeout before delegating to the original resolve, so the identity check always failed and the stale waiter was never removed. Fix: - Move waiter declaration before timer so the timeout callback can use indexOf(waiter) for correct object-identity lookup. - Track waitForState timers in pendingTimers so reset() cleans them up. - Remove timer from pendingTimers on resolve, reject, and timeout. - Delete the stateWaiters map entry when the last waiter is removed. Fixes #201 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a leak in the in-memory testing backend where waitForState() timeout handlers failed to remove stale waiters due to an identity/reference mismatch, causing stateWaiters to grow over time and timers to remain untracked across reset().
Changes:
- Fix waiter cleanup on timeout by removing the exact
waiterobject (indexOf(waiter)) rather than comparing function references. - Track
waitForState()timeout timers inpendingTimers, and remove them on resolve/reject/timeout soreset()can reliably clear them. - Add regression tests to ensure timed-out waiters are removed (both single-waiter and multi-waiter scenarios).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/durabletask-js/src/testing/in-memory-backend.ts | Fixes waitForState() timeout cleanup and ensures timeout timers are tracked/removed via pendingTimers. |
| packages/durabletask-js/test/in-memory-backend.spec.ts | Adds regression tests verifying stale waiter cleanup after timeouts (single and multiple waiters). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #201.
The
waitForStatetimeout handler failed to remove the stale waiter due to a reference mismatch, leaking waiters. This fixes the cleanup logic.Opens the existing fix branch
copilot-finds/bug/fix-waitforstate-timeout-cleanupas a PR (automated triage of active [copilot-finds] issues that had a ready fix branch but no open PR).