Skip to content

[Fix] Sync disconnect hangs and stale error status - #1108

Merged
simolus3 merged 13 commits into
mainfrom
fix/shared-worker-connector-call-timeout
Sep 21, 2026
Merged

simolus3 merged 13 commits into
mainfrom
fix/shared-worker-connector-call-timeout

Conversation

@Manrich121

@Manrich121 Manrich121 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Problem

disconnect() waits for the sync loops to finish. A checkpoint retry waiting on an already-aborted signal or a pending shared-worker connector call could prevent it from completing, leaving subsequent connect() calls pending.

Intentional disconnects could also leave a stale downloadError of Disconnect has been requested on the sync status.

Changes

  • Settle the checkpoint retry loop on disconnect. Handle signals that have already aborted and exit when checkpoint readiness is cancelled. This can happen when disconnect interrupts the retry delay and affects non-legacy checkpoint modes.
  • Cancel pending connector waits on disconnect. Forward the sync abort signal to uploadCrud and postCheckpointRequest, allowing the shared worker to stop waiting when disconnected. Connector calls have no timeout; fetchCredentials remains unbounded while its tab stays open.
  • Avoid reporting intentional disconnects as download errors. Check signal.aborted to distinguish requested disconnects from failures that should still be reported and retried.
  • Clear cached transient status when disposing the sync implementation. Prevent new tabs from inheriting stale errors while preserving core status, including hasSynced and lastSyncedAt.

Testing

TypeScript build passes. All 13 focused tests pass across checkpoint readiness, checkpoint retry cancellation, connector signal forwarding, and disconnect error reporting.

🤖 AI Disclosure

I used Claude Code Opus 5 to investigate the issue, implement the initial changes, and draft the original PR description. I used OpenAI Codex to review the changes, simplify comments, remove connector timeouts, and update this description.

@changeset-bot

changeset-bot Bot commented Sep 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0f578a5

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/web Patch
@powersync/adapter-sql-js Patch
@powersync/capacitor Patch
@powersync/node Patch
@powersync/react-native 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

Comment thread packages/shared-internals/src/client/BasePowerSyncDatabase.ts
@Manrich121
Manrich121 marked this pull request as ready for review September 17, 2026 11:03
@Manrich121 Manrich121 changed the title [Fix] Shared worker connect() hanging on an unresponsive tab [Fix] Sync disconnect hangs and stale error status Sep 17, 2026
@Manrich121
Manrich121 requested a review from simolus3 September 17, 2026 11:32
Comment thread .changeset/checkpoint-retry-disconnect-hang.md Outdated
Comment thread .changeset/stale-download-error-after-disconnect.md Outdated
Comment thread packages/shared-internals/tests/client/sync/stream/CheckpointDisconnect.test.ts Outdated
Comment thread packages/shared-internals/tests/client/sync/stream/ConnectorAbortSignal.test.ts Outdated
Comment thread packages/web/src/worker/sync/SharedSyncImplementation.ts
Comment thread packages/web/src/worker/sync/SharedSyncImplementation.ts Outdated
simolus3
simolus3 previously approved these changes Sep 18, 2026

@simolus3 simolus3 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you rebase ontop of / merge main? That contains a fix for the test action job not starting, apart from that this LGTM.

@simolus3
simolus3 force-pushed the fix/shared-worker-connector-call-timeout branch from 358a439 to 0f578a5 Compare September 21, 2026 10:18

@simolus3 simolus3 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need another +1 now. For context, I've added these commits to fix web reconnect tests.

I used Claude code to find the issue and implement the fix.

@simolus3
simolus3 requested a review from Chriztiaan September 21, 2026 10:25
@simolus3
simolus3 merged commit 7c80576 into main Sep 21, 2026
16 checks passed
@simolus3
simolus3 deleted the fix/shared-worker-connector-call-timeout branch September 21, 2026 10:56
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.

3 participants