Fix crud uploads for websockets #212
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thepowersync_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.