Skip to content

fix(powersync): use read lock for BucketStorage.select()#432

Open
rumitvn wants to merge 1 commit into
powersync-ja:mainfrom
rumitvn:fix/bucket-storage-select-readlock
Open

fix(powersync): use read lock for BucketStorage.select()#432
rumitvn wants to merge 1 commit into
powersync-ja:mainfrom
rumitvn:fix/bucket-storage-select-readlock

Conversation

@rumitvn

@rumitvn rumitvn commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Closes #384

Problem

BucketStorage.select() is documented "Use only for read statements", but it calls _internalDb.execute(), which acquires a write lock. Every caller (getClientId, updateLocalTarget, hasCrud, getCrudBatch, …) runs read-only SELECTs, so taking a write lock needlessly serializes these reads behind the write lock — notably on web / SqliteConnectionPool, where reads and writes can otherwise run concurrently.

@simolus3 confirmed in the issue that this is a bug.

Fix

Route select() through getAll(), which acquires a read lock, matching the method's documented read-only contract. All existing callers are plain SELECTs, so behaviour is unchanged apart from the correct lock type.

Notes

  • One-line behavioural change + CHANGELOG entry (## 2.3.1 (unreleased)).
  • No public API change.

BucketStorage.select() is documented for read statements only, but called
_internalDb.execute(), which acquires a write lock. All callers run SELECTs,
so route them through getAll() to take a read lock instead. This avoids
serializing read-only queries behind the write lock (e.g. on web with
SqliteConnectionPool).

Closes powersync-ja#384
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.

BucketStorage.select() uses execute() instead of getAll(), taking writeLock for read-only queries

1 participant