From 770484b78da4875d5a50f820538f2f9559f3498a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 26 Mar 2022 11:33:10 +0100 Subject: [PATCH 1/4] Failing test for #1194 --- .../ValueObservationPublisherTests.swift | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/Tests/GRDBCombineTests/ValueObservationPublisherTests.swift b/Tests/GRDBCombineTests/ValueObservationPublisherTests.swift index 755febc62..e8c80687b 100644 --- a/Tests/GRDBCombineTests/ValueObservationPublisherTests.swift +++ b/Tests/GRDBCombineTests/ValueObservationPublisherTests.swift @@ -423,5 +423,52 @@ class ValueObservationPublisherTests : XCTestCase { .runAtTemporaryDatabasePath { try setUp(DatabaseQueue(path: $0)) } .runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)) } } + + // MARK: - Regression Tests + + func testIssue1194() throws { + guard #available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *) else { + throw XCTSkip("Combine is not available") + } + + struct Record: Codable, FetchableRecord, PersistableRecord { + var id: Int64 + } + + var configuration = Configuration() + configuration.targetQueue = DispatchQueue(label: "crash.test", qos: .userInitiated) + + let database = DatabaseQueue(configuration: configuration) + + var migrator = DatabaseMigrator() + migrator.registerMigration("v1") { (db) in + try db.create(table: Record.databaseTableName) { (t) in + t.autoIncrementedPrimaryKey("id") + } + } + + try migrator.migrate(database) + + let observation = ValueObservation.tracking { (db) in + try Record.fetchCount(db) + } + + let exp = expectation(description: "") + let cancellable = observation.publisher(in: database, scheduling: .immediate) + .map { _ in + database.readPublisher { (db) in + try Record.fetchCount(db) + } + } + .switchToLatest() + .sink(receiveCompletion: { _ in }, + receiveValue: { (value) in + exp.fulfill() + }) + + withExtendedLifetime(cancellable) { + waitForExpectations(timeout: 1) + } + } } #endif From a3a26bf88f501b4d980ff47617a46ffdfe7cd35c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 26 Mar 2022 11:43:44 +0100 Subject: [PATCH 2/4] Fix #1194 --- GRDB/Core/Configuration.swift | 13 +++++++++++++ GRDB/ValueObservation/ValueConcurrentObserver.swift | 2 +- GRDB/ValueObservation/ValueWriteOnlyObserver.swift | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/GRDB/Core/Configuration.swift b/GRDB/Core/Configuration.swift index d8eeee059..ed3d47455 100644 --- a/GRDB/Core/Configuration.swift +++ b/GRDB/Core/Configuration.swift @@ -316,4 +316,17 @@ public struct Configuration { return DispatchQueue(label: label, qos: qos) } } + + /// Creates a DispatchQueue which has the quality of service of + /// read accesses. + /// + /// The returned queue has no target queue, and won't create deadlocks when + /// used synchronously from a database access. + func makeDispatchQueue(label: String) -> DispatchQueue { + if let targetQueue = targetQueue { + return DispatchQueue(label: label, qos: targetQueue.qos) + } else { + return DispatchQueue(label: label, qos: qos) + } + } } diff --git a/GRDB/ValueObservation/ValueConcurrentObserver.swift b/GRDB/ValueObservation/ValueConcurrentObserver.swift index cea80f6fe..cc829eb83 100644 --- a/GRDB/ValueObservation/ValueConcurrentObserver.swift +++ b/GRDB/ValueObservation/ValueConcurrentObserver.swift @@ -138,7 +138,7 @@ final class ValueConcurrentObserver { fetch: reducer._fetch) self.notificationCallbacks = NotificationCallbacks(events: events, onChange: onChange) self.reducer = reducer - self.reduceQueue = dbPool.configuration.makeReaderDispatchQueue(label: dbPool.configuration.identifier( + self.reduceQueue = dbPool.configuration.makeDispatchQueue(label: dbPool.configuration.identifier( defaultLabel: "GRDB", purpose: "ValueObservation")) } diff --git a/GRDB/ValueObservation/ValueWriteOnlyObserver.swift b/GRDB/ValueObservation/ValueWriteOnlyObserver.swift index 9e07516ff..2856c0b01 100644 --- a/GRDB/ValueObservation/ValueWriteOnlyObserver.swift +++ b/GRDB/ValueObservation/ValueWriteOnlyObserver.swift @@ -139,7 +139,7 @@ final class ValueWriteOnlyObserver Date: Sat, 26 Mar 2022 11:44:33 +0100 Subject: [PATCH 3/4] Documentation --- Tests/GRDBCombineTests/ValueObservationPublisherTests.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Tests/GRDBCombineTests/ValueObservationPublisherTests.swift b/Tests/GRDBCombineTests/ValueObservationPublisherTests.swift index e8c80687b..a30ed393a 100644 --- a/Tests/GRDBCombineTests/ValueObservationPublisherTests.swift +++ b/Tests/GRDBCombineTests/ValueObservationPublisherTests.swift @@ -426,6 +426,7 @@ class ValueObservationPublisherTests : XCTestCase { // MARK: - Regression Tests + /// Regression test for https://github.com/groue/GRDB.swift/issues/1194 func testIssue1194() throws { guard #available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *) else { throw XCTSkip("Combine is not available") From 8b120fa9b6d6f4b54300dcb51e3253a41533d3d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 26 Mar 2022 11:52:17 +0100 Subject: [PATCH 4/4] v5.22.1 --- CHANGELOG.md | 6 ++++++ GRDB.swift.podspec | 2 +- Makefile | 4 ++-- README.md | 4 ++-- Support/Info.plist | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 099d8abfb..21510f996 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -89,6 +89,12 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: --- +## 5.22.1 + +Released March 22, 2022 • [diff](https://github.com/groue/GRDB.swift/compare/v5.22.0...v5.22.1) + +- **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. + ## 5.22.0 Released March 22, 2022 • [diff](https://github.com/groue/GRDB.swift/compare/v5.21.0...v5.22.0) diff --git a/GRDB.swift.podspec b/GRDB.swift.podspec index bcdb819dd..56c10c4ce 100644 --- a/GRDB.swift.podspec +++ b/GRDB.swift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'GRDB.swift' - s.version = '5.22.0' + s.version = '5.22.1' s.license = { :type => 'MIT', :file => 'LICENSE' } s.summary = 'A toolkit for SQLite databases, with a focus on application development.' diff --git a/Makefile b/Makefile index 0708e837c..c3a48ed1b 100644 --- a/Makefile +++ b/Makefile @@ -538,8 +538,8 @@ ifdef JAZZY --author 'Gwendal Roué' \ --author_url https://github.com/groue \ --github_url https://github.com/groue/GRDB.swift \ - --github-file-prefix https://github.com/groue/GRDB.swift/tree/v5.22.0 \ - --module-version 5.22.0 \ + --github-file-prefix https://github.com/groue/GRDB.swift/tree/v5.22.1 \ + --module-version 5.22.1 \ --module GRDB \ --root-url http://groue.github.io/GRDB.swift/docs/5.22/ \ --output Documentation/Reference \ diff --git a/README.md b/README.md index 9701a46f7..2a4d89484 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,13 @@ --- -**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) +**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) **Requirements**: iOS 11.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+ • SQLite 3.8.5+ • Swift 5.3+ / Xcode 12+ | Swift version | GRDB version | | -------------- | ----------------------------------------------------------- | -| **Swift 5.3+** | **v5.22.0** | +| **Swift 5.3+** | **v5.22.1** | | Swift 5.2 | [v5.12.0](https://github.com/groue/GRDB.swift/tree/v5.12.0) | | Swift 5.1 | [v4.14.0](https://github.com/groue/GRDB.swift/tree/v4.14.0) | | Swift 5 | [v4.14.0](https://github.com/groue/GRDB.swift/tree/v4.14.0) | diff --git a/Support/Info.plist b/Support/Info.plist index 520d1b2ff..a2998f548 100644 --- a/Support/Info.plist +++ b/Support/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 5.22.0 + 5.22.1 CFBundleSignature ???? CFBundleVersion