Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(clerk-js): Prevent memory leak in worker timers setTimeout #4515

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

myandrienko
Copy link

@myandrienko myandrienko commented Nov 7, 2024

Description

When creating a timeout using worker timers, timeout callback is saved on the page side in map, and a mapping between page-side id and worker-side id is saved in an object in the worker.

Both of these entries are only cleaned up if the timeout is canceled with clearTimeout. Normally this isn't done. So even after timeout has fired, related entries are kept, causing a memory leak. It's especially noticeable when setTimeout is called recursively, as is done in Poller used by email link flow.

This PR cleans timeout-related entries once the timer has successfully fired.

Checklist

  • npm test runs as expected.
  • npm run build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Copy link

changeset-bot bot commented Nov 7, 2024

🦋 Changeset detected

Latest commit: 8912ef3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@clerk/clerk-js Patch
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@myandrienko myandrienko changed the title fix(clerk-js): prevent memory leak in worker timers setTimeout fix(clerk-js): Prevent memory leak in worker timers setTimeout Nov 7, 2024
Copy link
Member

@BRKalow BRKalow left a comment

Choose a reason for hiding this comment

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

Thanks!

@BRKalow BRKalow enabled auto-merge (squash) November 14, 2024 19:04
Copy link

vercel bot commented Nov 26, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 26, 2024 10:07pm

@myandrienko
Copy link
Author

@BRKalow Anything else I can do here to help this get merged?

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.

2 participants