Skip to content

fix: Cancel pending timer handles when purging orchestration instances#197

Open
YunchuWang wants to merge 1 commit intomainfrom
copilot-finds/bug/fix-timer-leak-on-purge
Open

fix: Cancel pending timer handles when purging orchestration instances#197
YunchuWang wants to merge 1 commit intomainfrom
copilot-finds/bug/fix-timer-leak-on-purge

Conversation

@YunchuWang
Copy link
Member

Fixes #188

Problem

InMemoryOrchestrationBackend.purge() deletes the orchestration instance from the store but does not cancel pending setTimeout handles created by processCreateTimerAction(). Timer handles leak, keeping the Node.js event loop alive unnecessarily (can cause Jest 'did not exit' warnings).

Changes

  • Add per-instance timer tracking map to associate timer handles with their orchestration instance
  • When purge() is called, cancel all timers for that instance and remove them from tracking
  • reset() continues to cancel all timers as before

The InMemoryOrchestrationBackend.purge() method deleted orchestration
instances from the store but did not cancel their pending setTimeout
handles. This caused timer handles to leak, keeping the Node.js event
loop alive unnecessarily and wasting resources until the timers
eventually fired and found no instance to act on.

The fix adds per-instance timer tracking via an instanceTimers map.
When purge() is called, all pending timers for that instance are
cancelled and removed from both the instance-level and global timer
tracking sets.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 23, 2026 22:53
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 a resource-leak in the InMemoryOrchestrationBackend test backend by ensuring durable timer setTimeout handles are canceled when a terminal orchestration instance is purged, preventing leaked timers from keeping the Node.js event loop alive (e.g., Jest “did not exit” warnings).

Changes:

  • Add per-instance timer tracking (instanceTimers) alongside the existing global pendingTimers.
  • Cancel and deregister all timers associated with an instance inside purge().
  • Add Jest coverage to validate timers are canceled for the purged instance only.

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 Track timer handles per orchestration instance and cancel them during purge; keep reset behavior clearing all timers.
packages/durabletask-js/test/in-memory-backend.spec.ts Add tests asserting purge cancels pending timers and doesn’t affect other instances’ timers.

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.

[copilot-finds] Bug: InMemoryOrchestrationBackend.purge() leaks pending timer handles

2 participants