Skip to content

Commit 044cf23

Browse files
authored
Prevent long-running tasks from preventing the database from closing (#54)
1 parent 4563f1c commit 044cf23

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

Sources/SQLite/SQLiteDatabase.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ public final class SQLiteDatabase: DatabaseProtocol, @unchecked Sendable {
114114
public func truncate() throws {
115115
switch database {
116116
case let .pool(pool):
117-
try pool.writeWithoutTransaction { db in
117+
try pool.barrierWriteWithoutTransaction { db in
118118
_ = try db.execute(raw: "PRAGMA wal_checkpoint(TRUNCATE);")
119119
}
120120

121121
case let .queue(queue):
122-
try queue.writeWithoutTransaction { db in
122+
try queue.barrierWriteWithoutTransaction { db in
123123
_ = try db.execute(raw: "PRAGMA wal_checkpoint(TRUNCATE);")
124124
}
125125
}
@@ -132,6 +132,7 @@ public final class SQLiteDatabase: DatabaseProtocol, @unchecked Sendable {
132132
switch database {
133133
case let .pool(pool):
134134
pool.interrupt()
135+
pool.invalidateReadOnlyConnections()
135136
try pool.close()
136137

137138
case let .queue(queue):

0 commit comments

Comments
 (0)