Skip to content

Shared worker: Immediate reconnect on connection interrupt#937

Open
simolus3 wants to merge 2 commits intomainfrom
shared-sync-worker-immediate-reconnect
Open

Shared worker: Immediate reconnect on connection interrupt#937
simolus3 wants to merge 2 commits intomainfrom
shared-sync-worker-immediate-reconnect

Conversation

@simolus3
Copy link
Copy Markdown
Contributor

When the sync process is managed by the Rust client as part of the SQLite extension, the client's state machine is coupled to the physical SQLite connection.

On the web, the shared sync worker use experience different connections over time as tabs are opened and closed. With the Rust sync client, attempting to handle a sync event on a connection without an active client throws. We recover from these (and all other sync errors) eventually, but it's not ideal:

  1. The cause of the error is a tab being closed, but we only realize this on the next sync event (e.g. a keepalive line sent roughly every 20 seconds).
  2. After each error, we wait for a configurable retry delay (5 seconds by default).

Issue 1 isn't problematic on its own (we don't really have anything to do without an event so we might as well use a broken connection), but issue 2 also means that we introduce a retry delay on the next checkpoint if it is sent before the next keepalive. This behavior is problematic and we should reconnect immediately to avoid this latency.

This PR fixes both issues: A field stores whether a connection may have been interrupted. If we get an "no iteration active" error from Rust while that field is set, we retry immediately instead of waiting for the retry delay (fixing issue 2). Also, we emit a bogus sync event as soon as the shared worker detects that the database may have been closed (fixing issue 1). This makes the Rust client much more usable on the web.

@simolus3 simolus3 requested a review from stevensJourney April 28, 2026 10:47
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 28, 2026

🦋 Changeset detected

Latest commit: 2d72e64

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

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