diff --git a/CHANGELOG.md b/CHANGELOG.md index 6545f5f6..b937b188 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 1.5.1 (unreleased) + +* Fix issue in legacy sync client where local writes made offline could have their upload delayed + until a keepalive event was received. This could also cause downloaded updates to be delayed even + further until all uploads were + completed. + ## 1.5.0 * Add `PowerSyncDatabase.getCrudTransactions()`, returning a flow of transactions. This is useful diff --git a/core/src/commonIntegrationTest/kotlin/com/powersync/sync/SyncIntegrationTest.kt b/core/src/commonIntegrationTest/kotlin/com/powersync/sync/SyncIntegrationTest.kt index 25bc868c..4d4db964 100644 --- a/core/src/commonIntegrationTest/kotlin/com/powersync/sync/SyncIntegrationTest.kt +++ b/core/src/commonIntegrationTest/kotlin/com/powersync/sync/SyncIntegrationTest.kt @@ -612,7 +612,6 @@ abstract class BaseSyncIntegrationTest( database.watch("SELECT name FROM users") { it.getString(0)!! }.testIn(scope) query.awaitItem() shouldBe listOf("local write") - syncLines.send(SyncLine.KeepAlive(tokenExpiresIn = 1234)) syncLines.send( SyncLine.FullCheckpoint( Checkpoint( diff --git a/core/src/commonMain/kotlin/com/powersync/sync/SyncStream.kt b/core/src/commonMain/kotlin/com/powersync/sync/SyncStream.kt index 3bacd18a..56b2c4b4 100644 --- a/core/src/commonMain/kotlin/com/powersync/sync/SyncStream.kt +++ b/core/src/commonMain/kotlin/com/powersync/sync/SyncStream.kt @@ -536,9 +536,20 @@ internal class SyncStream( lateinit var receiveLines: Job receiveLines = scope.launch { + var hadLine = false receiveTextLines(JsonUtil.json.encodeToJsonElement(req)).collect { value -> val line = JsonUtil.json.decodeFromString(value) + if (!hadLine) { + // Trigger a crud upload when receiving the first sync line: We could have + // pending local writes made while disconnected, so in addition to listening on + // updates to `ps_crud`, we also need to trigger a CRUD upload in some other + // cases. We do this on the first sync line because the client is likely to be + // online in that case. + hadLine = true + triggerCrudUploadAsync() + } + state = handleInstruction(line, value, state) if (state.abortIteration) {