Skip to content

fix: Fix createDiffTrigger deadlock when called with a setupContext on single-connection platforms#989

Merged
Chriztiaan merged 7 commits into
mainfrom
fix/trigger-setup-context
Jun 10, 2026
Merged

fix: Fix createDiffTrigger deadlock when called with a setupContext on single-connection platforms#989
Chriztiaan merged 7 commits into
mainfrom
fix/trigger-setup-context

Conversation

@Chriztiaan

@Chriztiaan Chriztiaan commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Fix for diff trigger lock context option introduced in #888.

Issue

In an app using @powersync/tanstack-db with the on-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:

  • I could only reproduce this on web. The Node-based tests for the tanstack-db PowerSync package ran fine.
  • Switching the web database to the OPFSWriteAheadVFS VFS made the application work, which pointed at connection/locking behaviour rather than the trigger logic itself.

Cause

The on-demand mode in tanstack-db calls createDiffTrigger from inside a write lock, passing that lock's
context in as setupContext. However, before createDiffTrigger ever used the provided context, it called getUUID(), which ran this.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 lf newlines instead of the default crlf.

AI Disclosure

I used Claude Fable to help investigate this problem.

@changeset-bot

changeset-bot Bot commented Jun 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6f2cff4

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

This PR includes changesets to release 7 packages
Name Type
@powersync/common Minor
@powersync/node 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

@Chriztiaan Chriztiaan changed the title fix: Fix createDiffTrigger deadlock when called with a setupContext on single-connection platforms fix: Fix createDiffTrigger deadlock when called with a setupContext on single-connection platforms Jun 10, 2026
@Chriztiaan Chriztiaan requested review from simolus3 and removed request for simolus3 June 10, 2026 12:28
@Chriztiaan Chriztiaan requested a review from simolus3 June 10, 2026 12:52
@Chriztiaan Chriztiaan marked this pull request as ready for review June 10, 2026 12:52
@Chriztiaan Chriztiaan merged commit 17869e7 into main Jun 10, 2026
16 checks passed
@Chriztiaan Chriztiaan deleted the fix/trigger-setup-context branch June 10, 2026 13:14
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