fix: Fix createDiffTrigger deadlock when called with a setupContext on single-connection platforms#989
Merged
Merged
Conversation
…ction environments.
🦋 Changeset detectedLatest commit: 6f2cff4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
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 |
createDiffTrigger deadlock when called with a setupContext on single-connection platforms
…owersync-js into fix/trigger-setup-context
simolus3
approved these changes
Jun 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix for diff trigger lock context option introduced in #888.
Issue
In an app using
@powersync/tanstack-dbwith theon-demandmode on web, live queries/collections never became ready and the database never reached a connected state. The app simply appeared stuck with no errors.Notably:
OPFSWriteAheadVFSVFS made the application work, which pointed at connection/locking behaviour rather than the trigger logic itself.Cause
The
on-demandmode intanstack-dbcallscreateDiffTriggerfrom inside a write lock, passing that lock'scontext in as
setupContext. However, beforecreateDiffTriggerever used the provided context, it calledgetUUID(),which ranthis.db.get(...), acquiring a new read lock on the database.On platforms where read and write access share a single connection queue (the default web setup), that nested read request queues behind the write lock the caller is still holding. This caused a deadlock.
This explains why we didn't see the issue for OPFSWriteAheadVFS as it supports separate write and read connections.
Testing
Tested by hand, and introduced a unit test that reproduced the issue - which also verified the problem was resolved after the code change.
Drive-by change
Changed the API extractor config to use
lfnewlines instead of the defaultcrlf.AI Disclosure
I used Claude Fable to help investigate this problem.