Skip to content

Fix stream subscription changes made during connect() - #1078

Open
joshuabrink wants to merge 2 commits into
mainfrom
fix/connect-window-subscription-drop
Open

Fix stream subscription changes made during connect()#1078
joshuabrink wants to merge 2 commits into
mainfrom
fix/connect-window-subscription-drop

Conversation

@joshuabrink

Copy link
Copy Markdown
Contributor

What happens

A subscribe() or unsubscribe() called, while connect() is bringing up the sync implementation, is never sent to the PowerSync Service. It returns normally and the client reports the new stream set, but the service keeps the set from when connect() started. The sets stay out of step until the set changes again or the connection restarts.

Why

packages/shared-internals/src/client/ConnectionManager.ts

// connectInternal(), :228
const { sync, onDispose } = await this.options.createSyncImplementation(connector, {
  subscriptions: this.activeStreams,        // (1) the set is read here
  serializedSchema: schema
});
this.syncStreamImplementation = sync;       // (3) only now can (2) reach the implementation

// :358
private subscriptionsMayHaveChanged() {
  this.syncStreamImplementation?.updateSubscriptions(this.activeStreams);   // (2) silent no-op
}

A change landing between (1) and (3) is lost: Too late for the set read at (1), and at (2) syncStreamImplementation is still null, so ?. skips the call without raising anything.

Fix

Save the identity of the set it read at (1), and then after (3) check for a difference, if true then update the stream set.

AI Disclosure

Claude Opus was used to build the reproduction and tests. Issue and fix manually verified.

@changeset-bot

changeset-bot Bot commented Aug 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 897cc30

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

This PR includes changesets to release 7 packages
Name Type
@powersync/shared-internals Patch
@powersync/adapter-sql-js Patch
@powersync/capacitor Patch
@powersync/node Patch
@powersync/react-native 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

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.

1 participant