Skip to content

Simplify control flow in sync client#410

Merged
simolus3 merged 3 commits into
mainfrom
fix-reconnect-delay-after-subscription-change
Apr 28, 2026
Merged

Simplify control flow in sync client#410
simolus3 merged 3 commits into
mainfrom
fix-reconnect-delay-after-subscription-change

Conversation

@simolus3
Copy link
Copy Markdown
Contributor

This closes #409. Previously, there was a potential race condition when adding new sync streams because we:

  1. First added a AbortCurrentIteration local sync event.
  2. Which is then handled asynchronously to break out of the client loop once handled, but it's possible for additional server-side events to come in before we get to that.

Instead of handling close events asynchronously, this refactors the control flow of the sync client, allowing us to just break out of a loop when the core extension tells us to instead of having to go through these hoops. We do this by making all instructions that won't interrupt a sync iteration extend a common class, so we can safely express which instructions we can handle in a separate methods and which ones need to be part of the loop.

This also updates the core extension and removes a workaround for a package:http bug related to cancelling streams on the web.

Comment thread packages/powersync/lib/src/sync/streaming_sync.dart
Comment thread packages/powersync/lib/src/sync/streaming_sync.dart
Comment thread packages/powersync/lib/src/sync/streaming_sync.dart
@simolus3 simolus3 requested a review from stevensJourney April 23, 2026 15:54
@simolus3 simolus3 marked this pull request as ready for review April 23, 2026 15:54
Copy link
Copy Markdown
Contributor

@stevensJourney stevensJourney left a comment

Choose a reason for hiding this comment

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

The changes here look good to me :)

Comment thread packages/powersync/lib/src/sync/streaming_sync.dart
@simolus3 simolus3 merged commit b61863b into main Apr 28, 2026
6 checks passed
@simolus3 simolus3 deleted the fix-reconnect-delay-after-subscription-change branch April 28, 2026 10:11
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.

Performance regression in desktop integration tests after upgrading 1.18.0 to 2.0.1

4 participants