Skip to content

fix(motion): prevent callback leak on detaching VirtualClock - #3734

Open
Unnati1007 wants to merge 1 commit into
Karanjot786:mainfrom
Unnati1007:fix/issue-3733-timer-pool-leak
Open

fix(motion): prevent callback leak on detaching VirtualClock#3734
Unnati1007 wants to merge 1 commit into
Karanjot786:mainfrom
Unnati1007:fix/issue-3733-timer-pool-leak

Conversation

@Unnati1007

Copy link
Copy Markdown
Contributor

Description

This PR fixes a permanent interval/callback leak inside the @termuijs/motion timer coalescing pool. When a VirtualClock is detached, active subscriptions are migrated back to the real timer pool. However, their returned unsub functions previously still pointed to the virtual clock's cleanup instead of the real timer pool. This PR tracks the active state of each subscription and correctly maps unsubscription back to the real pool when needed.

Related Issue

Closes #3733

Which package(s)?

@termuijs/motion

Type of Change

  • 🐛 Bug fix (type:bug)
  • ✨ Feature (type:feature)
  • 📝 Docs (type:docs)
  • 🧪 Tests (type:testing)
  • ♻️ Refactor (type:refactor)
  • 🎨 Design / UX (type:design)
  • ♿ Accessibility (type:accessibility)
  • ⚡ Performance (type:performance)
  • 🔧 DevOps / CI (type:devops)
  • 🔒 Security (type:security)

Checklist

  • ⭐ You starred the repo. The needs-star check blocks your merge otherwise.
  • Tests pass locally: bun vitest run
  • Build passes: bun run build
  • Typecheck passes: bun run typecheck
  • You read CONTRIBUTING.md.
  • Your PR title follows type: short description.
  • Widget state mutators call markDirty() (if your change affects rendering).
  • No new any types without an inline comment explaining why.
  • No unrelated refactors bundled into this PR.

GSSoC 2026 Participation

  • You are a GSSoC 2026 contributor.
  • Your GSSoC profile: https://gssoc.girlscript.org/profile/Unnati1007

Screenshots / Recordings (UI changes)

N/A (This is a non-visual background backend timing pool leak fix).

Notes for the Reviewer

  • Added a test case in timer-pool.test.ts verifying that calling unsub() after detaching a VirtualClock successfully unsubscribes the callback and cleans up the real timer intervals.

@github-actions github-actions Bot added type:testing +10 pts. Tests. type:bug +10 pts. Bug fix. labels Aug 10, 2026
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Unnati1007, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 9 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: bc3e39ce-fe83-4589-9e12-88d22a459a05

📥 Commits

Reviewing files that changed from the base of the PR and between e4472c9 and ac8bb04.

📒 Files selected for processing (2)
  • packages/motion/src/timer-pool.test.ts
  • packages/motion/src/timer-pool.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Unnati1007

Copy link
Copy Markdown
Contributor Author

@Karanjot786 Please review the PR, do lemme know if any changes needed and merge it under GSSoC'26

@Karanjot786

Copy link
Copy Markdown
Owner

Blocking — build-and-test fails on the PR own test (timer-pool.test.ts:120). Root cause: the migration loop (timer-pool.ts:96-103) never sets entry.active=false when moving a sub to the real pool, so the unsub closure takes the wrong branch and the callback stays registered — the exact leak claimed. Set active=false on migration.

@Karanjot786 Karanjot786 added the quality:needs-work Needs changes before merge. label Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

quality:needs-work Needs changes before merge. type:bug +10 pts. Bug fix. type:testing +10 pts. Tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(motion): Callback leak when detaching VirtualClock from shared interval timer pool

2 participants