Weird crash with Concurrency

Hi everyone :wave:

Since some time we have really weird crash in our concurrency stack :/

We made many research and tests but it's looking like totally random and I have no more idea now ...

Some examples :

Crashed: com.apple.root.user-initiated-qos.cooperative
0  libswift_Concurrency.dylib     0x43710 performEscalationAction(swift::TaskStatusRecord*, swift::JobPriority) + 28
1  libswift_Concurrency.dylib     0x43160 swift_task_escalateImpl(swift::AsyncTask*, swift::JobPriority) + 276
2  libswift_Concurrency.dylib     0x3ee04 swift::AsyncTask::waitFuture(swift::AsyncTask*, swift::AsyncContext*, void (swift::AsyncContext* swift_async_context) swiftasynccall*, swift::AsyncContext*, swift::OpaqueValue*) + 552
3  libswift_Concurrency.dylib     0x3f584 swift_task_future_wait_throwingImpl(swift::OpaqueValue*, swift::AsyncContext*, swift::AsyncTask*, void (swift::AsyncContext* swift_async_context, void* swift_context) swiftasynccall*, swift::AsyncContext*) + 144
4  libswift_Concurrency.dylib     0x3b7cc swift::runJobInEstablishedExecutorContext(swift::Job*) + 244
5  libswift_Concurrency.dylib     0x3c1e8 swift_job_runImpl(swift::Job*, swift::ExecutorRef) + 72
6  libdispatch.dylib              0x15164 _dispatch_root_queue_drain + 396
7  libdispatch.dylib              0x1596c _dispatch_worker_thread2 + 164
8  libsystem_pthread.dylib        0x1080 _pthread_wqthread + 228
9  libsystem_pthread.dylib        0xe5c start_wqthread + 8
Crashed: com.apple.root.user-initiated-qos.cooperative
0  libswift_Concurrency.dylib     0x30f9c waitForStatusRecordUnlock(swift::AsyncTask*, swift::ActiveTaskStatus&) + 72
1  libswift_Concurrency.dylib     0x2fd00 acquireStatusRecordLock(swift::AsyncTask*, llvm::Optional<(anonymous namespace)::StatusRecordLockRecord>&, LockContext) + 148
2  libswift_Concurrency.dylib     0x30c28 swift_task_escalateImpl(swift::AsyncTask*, swift::JobPriority) + 84
3  libswift_Concurrency.dylib     0x2da54 swift::AsyncTask::waitFuture(swift::AsyncTask*, swift::AsyncContext*, void (swift::AsyncContext* swift_async_context) swiftasynccall*, swift::AsyncContext*, swift::OpaqueValue*) + 480
4  libswift_Concurrency.dylib     0x2df68 swift_task_future_wait_throwingImpl(swift::OpaqueValue*, swift::AsyncContext*, swift::AsyncTask*, void (swift::AsyncContext* swift_async_context, void* swift_context) swiftasynccall*, swift::AsyncContext*) + 84
5  libswift_Concurrency.dylib     0x2b0f0 swift::runJobInEstablishedExecutorContext(swift::Job*) + 132
6  libswift_Concurrency.dylib     0x2b9f8 swift_job_runImpl(swift::Job*, swift::ExecutorRef) + 72
7  libdispatch.dylib              0x482f0 _dispatch_root_queue_drain + 328
8  libdispatch.dylib              0x48acc _dispatch_worker_thread2 + 160
9  libsystem_pthread.dylib        0x4e48 _pthread_wqthread + 224
10 libsystem_pthread.dylib        0x49f0 start_wqthread + 8
Crashed: NSOperationQueue 0x1075db8e0 (QOS: UNSPECIFIED)
0  libobjc.A.dylib                0x39c8 objc_retain + 8
1  CFNetwork                      0x42db0 CFURLRequestSetShouldStartSynchronously + 34084
2  CFNetwork                      0x4920c CFURLCacheCurrentDiskUsage + 1020
3  CFNetwork                      0x46dd4 CFURLRequestSetHTTPRequestBodyParts + 9196
4  BRApiKit                       0x57814 HTTPMetrics.init(metrics:task:) + 61 (HTTPMetrics.swift:61)
5  BRApiKit                       0x39f78 specialized HTTPDataLoader.urlSession(_:task:didFinishCollecting:) + 281 (HTTPDataLoader.swift:281)
6  BRApiKit                       0x38310 @objc HTTPDataLoader.urlSession(_:task:didFinishCollecting:) + 4409131792 (<compiler-generated>:4409131792)
7  CFNetwork                      0x26cf4 CFURLRequestCopyHTTPRequestBodyStream + 2320
8  Foundation                     0x51bfc __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 24
9  Foundation                     0x63f74 -[NSBlockOperation main] + 104
10 Foundation                     0x3c1f4 __NSOPERATION_IS_INVOKING_MAIN__ + 24
11 Foundation                     0x4d5bc -[NSOperation start] + 788
12 Foundation                     0x50c48 __NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION__ + 24
13 Foundation                     0x5edf0 __NSOQSchedule_f + 184
14 libdispatch.dylib              0x12830 _dispatch_block_async_invoke2 + 148
15 libdispatch.dylib              0x3a30 _dispatch_client_callout + 20
16 libdispatch.dylib              0x6eec _dispatch_continuation_pop + 500
17 libdispatch.dylib              0x65f0 _dispatch_async_redirect_invoke + 736
18 libdispatch.dylib              0x15164 _dispatch_root_queue_drain + 396
19 libdispatch.dylib              0x1596c _dispatch_worker_thread2 + 164
20 libsystem_pthread.dylib        0x1080 _pthread_wqthread + 228
21 libsystem_pthread.dylib        0xe5c start_wqthread + 8

We have many other like that :/
Any idea what we are missing and why we have some random crash like that ?
Thanks for your help :pray:

This looks like a known race in the current runtime which has been fixed in 5.7. Unfortunately, we do not currently have a solution for this race on previously-released runtimes.

2 Likes