Skip to content

Conversation

simolus3
Copy link
Contributor

@simolus3 simolus3 commented Jul 1, 2025

This first invokes the powersync_control method before attempting a CRUD upload for the first line.

The reason is that powersync_control will update the sync status to mark us as connected - which the CRUD upload logic checks for. This fixes another issue where we might not upload local changes when using the web socket transport protocol (thanks again @Radiokot for following up on this!).

This also fixes a potential race condition between the different jobs as part of the new sync implementation. E.g. we could have a request to close the stream and a concurrent completed CRUD upload - here it's important that we don't invoke powersync_control after closing the stream. So I've introduced a channel to ensure that we have a single coroutine taking care of the powersync_control invocations.

I've spent some time trying to get a mocked WebSocket + RSocket server to work in unit tests, but eventually gave up because the complexity seems quite high (it should be possible, but I'm not sure it's worth it). I've tested this change manually by creating a write in the demo while offline, then reconnecting and checking that new changes in Supabase sync down.

@simolus3 simolus3 requested a review from stevensJourney July 1, 2025 22:12
stevensJourney
stevensJourney previously approved these changes Jul 2, 2025
@Radiokot
Copy link
Contributor

Radiokot commented Jul 2, 2025

Thank you 👏🏻 Indeed, connecting multiple async processes to each other can quickly become tricky!

@simolus3 simolus3 requested a review from stevensJourney July 2, 2025 16:13
@simolus3 simolus3 merged commit fca069d into main Jul 3, 2025
9 of 12 checks passed
@simolus3 simolus3 deleted the fix-crud-uploads-for-ws branch July 3, 2025 18:46
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