Skip to content

Conversation

@FrederikBolding
Copy link
Member

@FrederikBolding FrederikBolding commented Nov 18, 2025

Adds a mutex per Snap that can be used to make usage of snap_setState in parallel more safe. The assumption was that this was already safe since getting and setting the state nearly always is a synchronous task. However, in practice, at least on mobile, this assumption has been proven false. This change may include a performance penalty, but it is important for snap_setState to be safe to use without data loss.


Note

Wraps snap_setState in a per-Snap mutex to safely handle parallel state updates and adds tests; updates deps and minor coverage thresholds.

  • snaps-rpc-methods:
    • State updates: Wrap snap_setState logic in a per-Snap async-mutex (getMutex, mutexes map, runExclusive) to serialize concurrent updates.
    • Types: Use SnapId for mutex keying.
    • Tests: Add concurrency test ensuring mutex serializes updates; adjust imports to use createDeferredPromise.
    • Dependencies: Add async-mutex.
    • Config: Slightly adjust Jest coverage thresholds.

Written by Cursor Bugbot for commit 358aad0. This will update automatically on new commits. Configure here.

@FrederikBolding FrederikBolding marked this pull request as ready for review November 18, 2025 14:59
@FrederikBolding FrederikBolding requested a review from a team as a code owner November 18, 2025 14:59
@codecov
Copy link

codecov bot commented Nov 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.28%. Comparing base (7ad4e66) to head (358aad0).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3742   +/-   ##
=======================================
  Coverage   98.28%   98.28%           
=======================================
  Files         418      418           
  Lines       12175    12184    +9     
  Branches     1886     1887    +1     
=======================================
+ Hits        11966    11975    +9     
  Misses        209      209           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@FrederikBolding FrederikBolding added this pull request to the merge queue Nov 18, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 18, 2025
@FrederikBolding FrederikBolding added this pull request to the merge queue Nov 19, 2025
Merged via the queue into main with commit c7e59b6 Nov 19, 2025
123 checks passed
@FrederikBolding FrederikBolding deleted the fb/set-state-mutex branch November 19, 2025 08:55
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.

3 participants