Skip to content

Commit 87cf718

Browse files
fix: transaction resulting in race condition when not using the correct context (#89)
* fix: transaction resulting in race condition when not using the correct context * chore: add changelog and version updates
1 parent cc0a8ea commit 87cf718

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.0.0-BETA12
4+
5+
* Use transaction context in `writeTransaction` in `BucketStorageImpl` to avoid race condition issues in Swift SDK.
6+
37
## 1.0.0-BETA11
48

59
* Update version to fix deployment issue of previous release

core/src/commonMain/kotlin/com/powersync/bucket/BucketStorageImpl.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ internal class BucketStorageImpl(
9393

9494
logger.i { "[updateLocalTarget] Updating target to checkpoint $opId" }
9595

96-
return db.writeTransaction {
96+
return db.writeTransaction { tx ->
9797
if (hasCrud()) {
9898
logger.w { "[updateLocalTarget] ps crud is not empty" }
9999
return@writeTransaction false
100100
}
101101

102102
val seqAfter =
103-
db.getOptional("SELECT seq FROM sqlite_sequence WHERE name = '${InternalTable.CRUD}'") {
103+
tx.getOptional("SELECT seq FROM sqlite_sequence WHERE name = '${InternalTable.CRUD}'") {
104104
it.getLong(0)!!
105105
}
106106
?: // assert isNotEmpty
@@ -112,7 +112,7 @@ internal class BucketStorageImpl(
112112
return@writeTransaction false
113113
}
114114

115-
db.execute(
115+
tx.execute(
116116
"UPDATE ${InternalTable.BUCKETS} SET target_op = CAST(? as INTEGER) WHERE name='\$local'",
117117
listOf(opId),
118118
)

0 commit comments

Comments
 (0)