Description
(originally reported in Slack #sqlite-data channel)
Quick repeating calls to load can occur naturally in situations like handling a deep link on application start: the application first loads the initial/default query, followed by a quick reload to process the deep link.
Investigation reveals that awaiting the FetchSubscription.task is what triggers this bug. There's a race between the cancellation of the task (which will occur when the await is situated inside a view's .task modifier) and the handling of the new load. If the cancel wins, it prevents the new load from succeeding, resulting in stale data.
See attached demo app for a controllable repro - SubscriptionTaskReloadRaceApp_1.12.0.zip. The app cycles between query states A -> B -> C -> D, which each have their respective expected results ([A,A..], [B, B, ..], etc.). The app will halt whenever displayed results do not match expected results based on the most recent load call. Lowering the "Replacement load delay" to below 100ms reliably triggers the mismatch/stale results state. repro video
Checklist
Expected behavior
Results provided by the @Fetch* wrapper always match with the latest load call.
Actual behavior
Results provided by the @Fetch* wrapper can get stuck on results corresponding to a previous load call instead of the latest.
Reproducing project
SubscriptionTaskReloadRaceApp_1.12.0.zip
SQLiteData version information
1.12.0
Sharing version information
2.10.1
GRDB version information
7.11.1
Destination operating system
iOS 27
Xcode version information
27.0
Swift Compiler version information
Description
(originally reported in Slack #sqlite-data channel)
Quick repeating calls to
loadcan occur naturally in situations like handling a deep link on application start: the application first loads the initial/default query, followed by a quick reload to process the deep link.Investigation reveals that awaiting the
FetchSubscription.taskis what triggers this bug. There's a race between the cancellation of the task (which will occur when the await is situated inside a view's.taskmodifier) and the handling of the new load. If the cancel wins, it prevents the new load from succeeding, resulting in stale data.See attached demo app for a controllable repro - SubscriptionTaskReloadRaceApp_1.12.0.zip. The app cycles between query states A -> B -> C -> D, which each have their respective expected results ([A,A..], [B, B, ..], etc.). The app will halt whenever displayed results do not match expected results based on the most recent load call. Lowering the "Replacement load delay" to below 100ms reliably triggers the mismatch/stale results state. repro video
Checklist
mainbranch of this package.Expected behavior
Results provided by the
@Fetch*wrapper always match with the latestloadcall.Actual behavior
Results provided by the
@Fetch*wrapper can get stuck on results corresponding to a previousloadcall instead of the latest.Reproducing project
SubscriptionTaskReloadRaceApp_1.12.0.zip
SQLiteData version information
1.12.0
Sharing version information
2.10.1
GRDB version information
7.11.1
Destination operating system
iOS 27
Xcode version information
27.0
Swift Compiler version information