Skip to content

Commit f3992a0

Browse files
committed
Merge branch 'development'
2 parents fafa74c + 8b120fa commit f3992a0

File tree

9 files changed

+75
-8
lines changed

9 files changed

+75
-8
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
8989

9090
---
9191

92+
## 5.22.1
93+
94+
Released March 22, 2022 • [diff](https://github.com/groue/GRDB.swift/compare/v5.22.0...v5.22.1)
95+
96+
- **Fixed** a 5.22.0 regression: [#1194](https://github.com/groue/GRDB.swift/issues/1194) ValueObservation could deadlock when the database is configured with a serial target DispatchQueue.
97+
9298
## 5.22.0
9399

94100
Released March 22, 2022 • [diff](https://github.com/groue/GRDB.swift/compare/v5.21.0...v5.22.0)

GRDB.swift.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'GRDB.swift'
3-
s.version = '5.22.0'
3+
s.version = '5.22.1'
44

55
s.license = { :type => 'MIT', :file => 'LICENSE' }
66
s.summary = 'A toolkit for SQLite databases, with a focus on application development.'

GRDB/Core/Configuration.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,4 +316,17 @@ public struct Configuration {
316316
return DispatchQueue(label: label, qos: qos)
317317
}
318318
}
319+
320+
/// Creates a DispatchQueue which has the quality of service of
321+
/// read accesses.
322+
///
323+
/// The returned queue has no target queue, and won't create deadlocks when
324+
/// used synchronously from a database access.
325+
func makeDispatchQueue(label: String) -> DispatchQueue {
326+
if let targetQueue = targetQueue {
327+
return DispatchQueue(label: label, qos: targetQueue.qos)
328+
} else {
329+
return DispatchQueue(label: label, qos: qos)
330+
}
331+
}
319332
}

GRDB/ValueObservation/ValueConcurrentObserver.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ final class ValueConcurrentObserver<Reducer: ValueReducer> {
138138
fetch: reducer._fetch)
139139
self.notificationCallbacks = NotificationCallbacks(events: events, onChange: onChange)
140140
self.reducer = reducer
141-
self.reduceQueue = dbPool.configuration.makeReaderDispatchQueue(label: dbPool.configuration.identifier(
141+
self.reduceQueue = dbPool.configuration.makeDispatchQueue(label: dbPool.configuration.identifier(
142142
defaultLabel: "GRDB",
143143
purpose: "ValueObservation"))
144144
}

GRDB/ValueObservation/ValueWriteOnlyObserver.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ final class ValueWriteOnlyObserver<Writer: DatabaseWriter, Reducer: ValueReducer
139139
fetch: reducer._fetch)
140140
self.notificationCallbacks = NotificationCallbacks(events: events, onChange: onChange)
141141
self.reducer = reducer
142-
self.reduceQueue = writer.configuration.makeReaderDispatchQueue(label: writer.configuration.identifier(
142+
self.reduceQueue = writer.configuration.makeDispatchQueue(label: writer.configuration.identifier(
143143
defaultLabel: "GRDB",
144144
purpose: "ValueObservation"))
145145
}

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,8 @@ ifdef JAZZY
538538
--author 'Gwendal Roué' \
539539
--author_url https://github.com/groue \
540540
--github_url https://github.com/groue/GRDB.swift \
541-
--github-file-prefix https://github.com/groue/GRDB.swift/tree/v5.22.0 \
542-
--module-version 5.22.0 \
541+
--github-file-prefix https://github.com/groue/GRDB.swift/tree/v5.22.1 \
542+
--module-version 5.22.1 \
543543
--module GRDB \
544544
--root-url http://groue.github.io/GRDB.swift/docs/5.22/ \
545545
--output Documentation/Reference \

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111

1212
---
1313

14-
**Latest release**: March 22, 2022 • [version 5.22.0](https://github.com/groue/GRDB.swift/tree/v5.22.0)[CHANGELOG](CHANGELOG.md)[Migrating From GRDB 4 to GRDB 5](Documentation/GRDB5MigrationGuide.md)
14+
**Latest release**: March 26, 2022 • [version 5.22.1](https://github.com/groue/GRDB.swift/tree/v5.22.1)[CHANGELOG](CHANGELOG.md)[Migrating From GRDB 4 to GRDB 5](Documentation/GRDB5MigrationGuide.md)
1515

1616
**Requirements**: iOS 11.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+ &bull; SQLite 3.8.5+ &bull; Swift 5.3+ / Xcode 12+
1717

1818
| Swift version | GRDB version |
1919
| -------------- | ----------------------------------------------------------- |
20-
| **Swift 5.3+** | **v5.22.0** |
20+
| **Swift 5.3+** | **v5.22.1** |
2121
| Swift 5.2 | [v5.12.0](https://github.com/groue/GRDB.swift/tree/v5.12.0) |
2222
| Swift 5.1 | [v4.14.0](https://github.com/groue/GRDB.swift/tree/v4.14.0) |
2323
| Swift 5 | [v4.14.0](https://github.com/groue/GRDB.swift/tree/v4.14.0) |

Support/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>5.22.0</string>
18+
<string>5.22.1</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

Tests/GRDBCombineTests/ValueObservationPublisherTests.swift

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,5 +423,53 @@ class ValueObservationPublisherTests : XCTestCase {
423423
.runAtTemporaryDatabasePath { try setUp(DatabaseQueue(path: $0)) }
424424
.runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)) }
425425
}
426+
427+
// MARK: - Regression Tests
428+
429+
/// Regression test for https://github.com/groue/GRDB.swift/issues/1194
430+
func testIssue1194() throws {
431+
guard #available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *) else {
432+
throw XCTSkip("Combine is not available")
433+
}
434+
435+
struct Record: Codable, FetchableRecord, PersistableRecord {
436+
var id: Int64
437+
}
438+
439+
var configuration = Configuration()
440+
configuration.targetQueue = DispatchQueue(label: "crash.test", qos: .userInitiated)
441+
442+
let database = DatabaseQueue(configuration: configuration)
443+
444+
var migrator = DatabaseMigrator()
445+
migrator.registerMigration("v1") { (db) in
446+
try db.create(table: Record.databaseTableName) { (t) in
447+
t.autoIncrementedPrimaryKey("id")
448+
}
449+
}
450+
451+
try migrator.migrate(database)
452+
453+
let observation = ValueObservation.tracking { (db) in
454+
try Record.fetchCount(db)
455+
}
456+
457+
let exp = expectation(description: "")
458+
let cancellable = observation.publisher(in: database, scheduling: .immediate)
459+
.map { _ in
460+
database.readPublisher { (db) in
461+
try Record.fetchCount(db)
462+
}
463+
}
464+
.switchToLatest()
465+
.sink(receiveCompletion: { _ in },
466+
receiveValue: { (value) in
467+
exp.fulfill()
468+
})
469+
470+
withExtendedLifetime(cancellable) {
471+
waitForExpectations(timeout: 1)
472+
}
473+
}
426474
}
427475
#endif

0 commit comments

Comments
 (0)