Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
groue committed Apr 2, 2022
2 parents bec58a3 + 0324f59 commit 15c06e0
Show file tree
Hide file tree
Showing 8 changed files with 256 additions and 223 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:

#### 5.x Releases

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

---

## 5.22.2

Released April 2, 2022 • [diff](https://github.com/groue/GRDB.swift/compare/v5.22.1...v5.22.2)

- **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

## 5.22.1

Released March 26, 2022 • [diff](https://github.com/groue/GRDB.swift/compare/v5.22.0...v5.22.1)
Expand Down
2 changes: 1 addition & 1 deletion GRDB.swift.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'GRDB.swift'
s.version = '5.22.1'
s.version = '5.22.2'

s.license = { :type => 'MIT', :file => 'LICENSE' }
s.summary = 'A toolkit for SQLite databases, with a focus on application development.'
Expand Down
3 changes: 2 additions & 1 deletion GRDB/ValueObservation/ValueConcurrentObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ extension ValueConcurrentObserver {
(self.notificationCallbacks, self.databaseAccess)
}
guard let notificationCallbacks = notificationCallbacksOpt, let databaseAccess = databaseAccessOpt else {
// Likely a GRDB bug
// Likely a GRDB bug: during a synchronous start, user is not
// able to cancel observation.
fatalError("can't start a cancelled or failed observation")
}

Expand Down
24 changes: 15 additions & 9 deletions GRDB/ValueObservation/ValueWriteOnlyObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ extension ValueWriteOnlyObserver {
(self.notificationCallbacks, self.databaseAccess)
}
guard let notificationCallbacks = notificationCallbacksOpt, let writer = databaseAccessOpt?.writer else {
// Likely a GRDB bug
// Likely a GRDB bug: during a synchronous start, user is not
// able to cancel observation.
fatalError("can't start a cancelled or failed observation")
}

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

// Reduce
return reduceQueue.sync {
Expand All @@ -218,12 +223,11 @@ extension ValueWriteOnlyObserver {
// Start from a write access, so that self can register as a
// transaction observer.
writer.asyncWriteWithoutTransaction { db in
let isNotifying = self.lock.synchronized { self.notificationCallbacks != nil }
guard isNotifying else { return /* Cancelled */ }

do {
// Fetch & Start observing the database
let fetchedValue = try self.fetchAndStartObservation(db)
guard let fetchedValue = try self.fetchAndStartObservation(db) else {
return /* Cancelled */
}

// Reduce
//
Expand Down Expand Up @@ -257,17 +261,19 @@ extension ValueWriteOnlyObserver {

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

switch trackingMode {
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.1 \
--module-version 5.22.1 \
--github-file-prefix https://github.com/groue/GRDB.swift/tree/v5.22.2 \
--module-version 5.22.2 \
--module GRDB \
--root-url http://groue.github.io/GRDB.swift/docs/5.22/ \
--output Documentation/Reference \
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

---

**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)
**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)

**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.1** |
| **Swift 5.3+** | **v5.22.2** |
| 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) |
Expand Down
2 changes: 1 addition & 1 deletion Support/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>5.22.1</string>
<string>5.22.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
Loading

0 comments on commit 15c06e0

Please sign in to comment.