Skip to content

Simplify control flow in sync iteration - #82

Merged
Chriztiaan merged 8 commits into
mainfrom
sync-client-control-flow
Aug 4, 2026
Merged

Simplify control flow in sync iteration#82
Chriztiaan merged 8 commits into
mainfrom
sync-client-control-flow

Conversation

@Chriztiaan

@Chriztiaan Chriztiaan commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

This ports similar changes from the JS SDK (itself a port of powersync.dart#410) to the sync client in the .NET SDK.

Addresses #81.

When a sync stream closed, a few already-queued messages could still be sent to the sync core after it had stopped listening. Those turned into No iteration is active errors that surfaced in crash reporting without the app being
able to catch them.

The iteration now processes everything in one sequential loop rather than alongside a background task, so once a stream ends nothing further is sent. Also uses the core's newer connection command to report connect/disconnect state instead of setting it manually, and makes stream read failures flow into the normal retry path.

AI disclosure

This PR was created with the help of Claude Opus 4.8. Help constitutes assistance in research, planning, and rough outline of implementation. Beyond having a hand in the implementation, I have also manually tested this work.

@Chriztiaan
Chriztiaan requested a review from LucDeCaf July 27, 2026 12:10
Comment thread PowerSync/PowerSync.Common/Client/Sync/Stream/CoreInstructions.cs Outdated
`NonInterruptingInstruction` abstract subclass, matching powersync.dart.
@Chriztiaan
Chriztiaan marked this pull request as ready for review July 28, 2026 09:53
Comment thread Tests/PowerSync/PowerSync.Common.Tests/Client/Sync/SyncIterationTeardownTests.cs Outdated

@LucDeCaf LucDeCaf 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.

The main implementation looks good to me, it mostly matches the quick-and-dirty version I made when I first checked out #81.

I ran this by Opus 5 to see if it could spot anything; it found a few potential races/guaranteed retries which we worked on fixing (it also found a number of issues which didn't actually exist, of course.)

The brief summary is that the socket dying or the iteration ending at the wrong time could cause an exception to be thrown or resources to not always be cleaned up, plus a small regression where CloseSyncStream.hide_disconnect's value is ignored.

@LucDeCaf
LucDeCaf requested a review from simolus3 August 3, 2026 14:47
@Chriztiaan
Chriztiaan merged commit e210882 into main Aug 4, 2026
5 checks passed
@Chriztiaan
Chriztiaan deleted the sync-client-control-flow branch August 4, 2026 11:34
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