I’m seeing a crash relating to TaskGroup
, but unfortunately it’s only coming up in production and I have limited information on it (via Crashlytics). I’m guessing I’m abusing TaskGroup
one way or another. Any advice as to where to start investigating an issue like this? Here’s the offending thread. I’ve tried at length to reproduce it locally but no luck.
Crashed: com.apple.root.user-initiated-qos.cooperative
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000040
Crashed: com.apple.root.user-initiated-qos.cooperative
0 libswift_Concurrency.dylib 0x31440 swift::TaskGroup::offer(swift::AsyncTask*, swift::AsyncContext*) + 504
1 libswift_Concurrency.dylib 0x2dc5c swift::AsyncTask::completeFuture(swift::AsyncContext*) + 132
2 libswift_Concurrency.dylib 0x2f4d0 completeTaskAndRelease(swift::AsyncContext*, swift::SwiftError*) + 128
3 libswift_Concurrency.dylib 0x2b0f0 swift::runJobInEstablishedExecutorContext(swift::Job*) + 132
4 libswift_Concurrency.dylib 0x2b9f8 swift_job_runImpl(swift::Job*, swift::ExecutorRef) + 72
5 libdispatch.dylib 0x1343c _dispatch_root_queue_drain + 340
6 libdispatch.dylib 0x13c38 _dispatch_worker_thread2 + 172
7 libsystem_pthread.dylib 0x4e48 _pthread_wqthread + 224
8 libsystem_pthread.dylib 0x49f0 start_wqthread + 8
I have only one use of TaskGroup
in my project, and it seems pretty trivial.
// Function that processes a bunch of 'action triggers' and produces a stream of actions
func run(action: Action, find: @escaping (Model.Type) -> Model?) -> AsyncStream<Action> {
AsyncStream { continuation in
Task {
await withTaskGroup(of: Void.self) { group in
for trigger in triggers {
group.addTask {
for await result in trigger(action, find) {
if result is VoidAction { continue }
continuation.yield(result)
}
}
}
await group.waitForAll()
continuation.finish()
}
}
}
}
// Later, from an async context. Process an action and dispatch its output.
Task {
for await output in run(action: action, find: { store.find($0) }) {
try await store.dispatch(output)
}
}
Is there any way to dig into this without a more complete crash report?