Skip to content

Commit 2151283

Browse files
committed
Fix race condition: prevent cancellation from cancelling other database accesses after database accesses has completed
Before this change, cancelling a database access could cancel *another* database access 😱
1 parent c5283a0 commit 2151283

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

GRDB/Core/DatabasePool.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,7 @@ extension DatabasePool: DatabaseWriter {
803803
try Task.checkCancellation()
804804
return try writer.sync { db in
805805
defer {
806+
cancelMutex.store(nil)
806807
db.uncancel()
807808
}
808809
cancelMutex.store(db.cancel)

GRDB/Core/SerializedDatabase.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ final class SerializedDatabase {
256256
return try await withTaskCancellationHandler {
257257
try await actor.execute {
258258
defer {
259+
cancelMutex.store(nil)
259260
db.uncancel()
260261
preconditionNoUnsafeTransactionLeft(db)
261262
}

0 commit comments

Comments
 (0)