Skip to content

Remove Old Mutex #662

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

Merged
merged 7 commits into from
Jul 11, 2025
Merged

Remove Old Mutex #662

merged 7 commits into from
Jul 11, 2025

Conversation

stevensJourney
Copy link
Collaborator

Overview

The very first version of the JS SDK used a shared mutex instance for read and write locks. Future versions moved the locking to the DBAdapter interface.

The AbstractPowerSyncDatabase still contained the shared mutex code which was used in the common readLock and writeLock implementations.

Using the same mutex for readLock and writeLock breaks concurrency. The React native SDK had an override for the readLock and writeLock method which avoided this issue. Web only has a single connection, so concurrency wasn't an issue there. The Node.js SDK however would rely on the common implementation and would therefore have some concurrency issues. Luckily the individual get, getAll and getOptional methods go through the DBAdapter and not the readLock API. Currency was only partially broken for the Node.js SDK.

This PR removes the old mutex entirely.

Copy link

changeset-bot bot commented Jul 11, 2025

🦋 Changeset detected

Latest commit: 88fbaf8

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

This PR includes changesets to release 7 packages
Name Type
@powersync/node Patch
@powersync/common Patch
@powersync/op-sqlite Patch
@powersync/react-native Patch
@powersync/tanstack-react-query Patch
@powersync/web Patch
@powersync/diagnostics-app 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

@rkistner
Copy link
Contributor

What was affected by this?

@stevensJourney
Copy link
Collaborator Author

The only affect I can think of is in the Node.js SDK: calls to readLock and writeLock would be wrapped in a shared mutex. Calling readLock in a writeLock and vice-versa would hang. Calls would also be executed sequentially.

@stevensJourney stevensJourney marked this pull request as ready for review July 11, 2025 14:08
@stevensJourney stevensJourney requested a review from rkistner July 11, 2025 14:08
@stevensJourney stevensJourney merged commit 9fb898d into main Jul 11, 2025
9 checks passed
@stevensJourney stevensJourney deleted the write_lock_fix branch July 11, 2025 14:30
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