Skip to content

Commit 15c06e0

Browse files
committed
Merge branch 'development'
2 parents bec58a3 + 0324f59 commit 15c06e0

File tree

8 files changed

+256
-223
lines changed

8 files changed

+256
-223
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
77

88
#### 5.x Releases
99

10-
- `5.22.x` Releases - [5.22.0](#5220) | [5.22.1](#5221)
10+
- `5.22.x` Releases - [5.22.0](#5220) | [5.22.1](#5221) | [5.22.2](#5222)
1111
- `5.21.x` Releases - [5.21.0](#5210)
1212
- `5.20.x` Releases - [5.20.0](#5200)
1313
- `5.19.x` Releases - [5.19.0](#5190)
@@ -89,6 +89,12 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
8989

9090
---
9191

92+
## 5.22.2
93+
94+
Released April 2, 2022 • [diff](https://github.com/groue/GRDB.swift/compare/v5.22.1...v5.22.2)
95+
96+
- **Fixed** a 5.22.0 regression: [#1196](https://github.com/groue/GRDB.swift/pull/1196) by [@layoutSubviews](https://github.com/layoutSubviews): Fix a crash when an observation is quickly cancelled
97+
9298
## 5.22.1
9399

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

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.1'
3+
s.version = '5.22.2'
44

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

GRDB/ValueObservation/ValueConcurrentObserver.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ extension ValueConcurrentObserver {
192192
(self.notificationCallbacks, self.databaseAccess)
193193
}
194194
guard let notificationCallbacks = notificationCallbacksOpt, let databaseAccess = databaseAccessOpt else {
195-
// Likely a GRDB bug
195+
// Likely a GRDB bug: during a synchronous start, user is not
196+
// able to cancel observation.
196197
fatalError("can't start a cancelled or failed observation")
197198
}
198199

GRDB/ValueObservation/ValueWriteOnlyObserver.swift

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ extension ValueWriteOnlyObserver {
155155
(self.notificationCallbacks, self.databaseAccess)
156156
}
157157
guard let notificationCallbacks = notificationCallbacksOpt, let writer = databaseAccessOpt?.writer else {
158-
// Likely a GRDB bug
158+
// Likely a GRDB bug: during a synchronous start, user is not
159+
// able to cancel observation.
159160
fatalError("can't start a cancelled or failed observation")
160161
}
161162

@@ -198,7 +199,11 @@ extension ValueWriteOnlyObserver {
198199
// from a database access.
199200
try writer.unsafeReentrantWrite { db in
200201
// Fetch & Start observing the database
201-
let fetchedValue = try fetchAndStartObservation(db)
202+
guard let fetchedValue = try fetchAndStartObservation(db) else {
203+
// Likely a GRDB bug: during a synchronous start, user is not
204+
// able to cancel observation.
205+
fatalError("can't start a cancelled or failed observation")
206+
}
202207

203208
// Reduce
204209
return reduceQueue.sync {
@@ -218,12 +223,11 @@ extension ValueWriteOnlyObserver {
218223
// Start from a write access, so that self can register as a
219224
// transaction observer.
220225
writer.asyncWriteWithoutTransaction { db in
221-
let isNotifying = self.lock.synchronized { self.notificationCallbacks != nil }
222-
guard isNotifying else { return /* Cancelled */ }
223-
224226
do {
225227
// Fetch & Start observing the database
226-
let fetchedValue = try self.fetchAndStartObservation(db)
228+
guard let fetchedValue = try self.fetchAndStartObservation(db) else {
229+
return /* Cancelled */
230+
}
227231

228232
// Reduce
229233
//
@@ -257,17 +261,19 @@ extension ValueWriteOnlyObserver {
257261

258262
/// Fetches the initial value, and start observing the database.
259263
///
264+
/// Returns nil if the observation was cancelled before database observation
265+
/// could start.
266+
///
260267
/// By grouping the initial fetch and the beginning of observation in a
261268
/// single database access, we are sure that no concurrent write can happen
262269
/// during the initial fetch, and that we won't miss any future change.
263-
private func fetchAndStartObservation(_ db: Database) throws -> Reducer.Fetched {
270+
private func fetchAndStartObservation(_ db: Database) throws -> Reducer.Fetched? {
264271
// TODO: [SR-214] remove -Opt suffix when we only support Xcode 12.5.1+
265272
let (eventsOpt, fetchOpt) = lock.synchronized {
266273
(notificationCallbacks?.events, databaseAccess?.fetch)
267274
}
268275
guard let events = eventsOpt, let fetch = fetchOpt else {
269-
// Likely a GRDB bug
270-
fatalError("can't start a cancelled or failed observation")
276+
return nil /* Cancelled */
271277
}
272278

273279
switch trackingMode {

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.1 \
542-
--module-version 5.22.1 \
541+
--github-file-prefix https://github.com/groue/GRDB.swift/tree/v5.22.2 \
542+
--module-version 5.22.2 \
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 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)
14+
**Latest release**: April 2, 2022 • [version 5.22.2](https://github.com/groue/GRDB.swift/tree/v5.22.2)[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+ • SQLite 3.8.5+ • Swift 5.3+ / Xcode 12+
1717

1818
| Swift version | GRDB version |
1919
| -------------- | ----------------------------------------------------------- |
20-
| **Swift 5.3+** | **v5.22.1** |
20+
| **Swift 5.3+** | **v5.22.2** |
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.1</string>
18+
<string>5.22.2</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

0 commit comments

Comments
 (0)