CareKit live streaming crashes with multithreaded violations
Dlemex opened this issue · 4 comments
Inside a swiftUI view using live streaming with @CareStoreFetchRequest
with core data concurrency debugging enabled will crash in OCKCDTask.makeTask()
as the OCKStore.tasks(matching:)
is performed on a cooperative thread. The problems continue for events and outcomes as well. The problems also occur with iOS, as I discovered this inside during development.
The attached sample is a modified version of ParseCareKit. To reproduce the issue, enable concurrency debugging for the watch target. You can just run the target, and the error will happen.
Hey @Dlemex, thanks for spotting this issue. We've seen this on our end as well and it's a top priority to fix. When you say you've seen the problem occur on iOS, are you also seeing the issue occur on other platforms?
I have only been using that on the iOS side, as my watch app is not using the new fetch request as of yet.
I have worked around the issue in the ugliest but working kludge. In OCKStore+Tasks, I change the map to (OCKStore+Outcomes got a similar fix):
let tasks = coreDataTasks
.map { tasks in
tasks.map { cdTask in
var task: OCKTask?
cdTask.managedObjectContext!.performAndWait {
task = cdTask.makeTask()
}
return task!
}
}
Nice workaround @Dlemex! We've implemented your fix in the latest beta release. I'll go ahead and close out this issue, but if the issue happens to persist feel free to open it back up.
https://github.com/carekit-apple/CareKit/releases/tag/3.0.1-beta.2