App hangs when two threads call URL.appendingPathComponent()

A customer reported that my app hangs at some point and he sent me a process analysis taken from Activity Monitor. To me it looks like two threads are calling URL.appendingPathComponent() at the same time and this causes a deadlock. Anyone knows how to avoid this and if this is a problem with macOS?


Call graph:
    2662 Thread_13677   DispatchQueue_1: com.apple.main-thread (serial)
    + 2662 start  (in libdyld.dylib) + 1  [0x7fff632ce7fd]
    +   2662 ???  (in myApp)  load address 0x1086d0000 + 0x1bb9  [0x1086d1bb9]
    +     2662 NSApplicationMain  (in AppKit) + 777 [0x7fff28dfc775]
    +       2662 -[NSApplication run]  (in AppKit) + 658 [0x7fff28e2a3ae]
    +         2662 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]  (in AppKit) + 1352  [0x7fff28e38690]
    +           2662 _DPSNextEvent  (in AppKit) + 990 [0x7fff28e39eb4]
    +             2662 _BlockUntilNextEventMatchingListInModeWithFilter  (in HIToolbox) + 64  [0x7fff2a7c8127]
    +               2662 ReceiveNextEventCommon  (in HIToolbox) + 600  [0x7fff2a7c839d]
    +                 2662 RunCurrentEventLoopInMode  (in HIToolbox) + 292  [0x7fff2a7c865d]
    +                   2662 CFRunLoopRunSpecific  (in CoreFoundation) + 499  [0x7fff2bc71bd3]
    +                     2662 __CFRunLoopRun  (in CoreFoundation) + 2370  [0x7fff2bc72b8a]
    +                       2662 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__  (in CoreFoundation) + 9  [0x7fff2bcb2e00]
    +                         2662 _dispatch_main_queue_callback_4CF  (in libdispatch.dylib) + 1105 [0x7fff63280bc4]
    +                           2662 _dispatch_client_callout  (in libdispatch.dylib) + 8  [0x7fff6327550e]
    +                             2662 _dispatch_call_block_and_release  (in libdispatch.dylib) + 12 [0x7fff63274583]
    +                               2662 ???  (in myApp)  load address 0x1086d0000 + 0xa3169  [0x108773169]
    +                                 2662 ???  (in myApp) load address 0x1086d0000 + 0x25f1e  [0x1086f5f1e]
    +                                   2662 ???  (in myApp) load address 0x1086d0000 + 0x26201  [0x1086f6201]
    +                                     2662 ???  (in myApp) load address 0x1086d0000 + 0x87eb7  [0x108757eb7]
    +                                       2662 ???  (in myApp)  load address 0x1086d0000 + 0x81da1  [0x108751da1]
    +                                         2662 ???  (in myApp)  load address 0x1086d0000 + 0x6d18  [0x1086d6d18]
    +                                           2662 URL.appendingPathComponent(_:)  (in libswiftFoundation.dylib) + 61  [0x7fff62e1e3ad]
    +                                             2662 -[NSURL(NSURLPathUtilities) URLByAppendingPathComponent:]  (in Foundation) + 217  [0x7fff2e2e843a]
    +                                               2662 -[NSURL getResourceValue:forKey:error:]  (in CoreFoundation) + 110 [0x7fff2bc5d4ff]
    +                                                 2662 CFURLCopyResourcePropertyForKey  (in CoreFoundation) + 119 [0x7fff2bc46958]
    +                                                   2662 _FSURLCopyResourcePropertyForKeyInternal(__CFURL const*, __CFString const*, void*, void*, __CFError**, unsigned char)  (in CoreServicesInternal) + 221  [0x7fff4472feba]
    +                                                     2662 prepareValuesForBitmap(__CFURL const*, __FileCache*, _FilePropertyBitmap*, __CFError**)  (in CoreServicesInternal) + 363  [0x7fff447337e4]
    +                                                       2662 corePropertyProviderPrepareValues(__CFURL const*, __FileCache*, __CFString const* const*, void const**, long, void const*, __CFError**)  (in CoreServicesInternal) + 631  [0x7fff44733ac4]
    +                                                         2662 __getattrlist  (in libsystem_kernel.dylib) + 10  [0x7fff6340fad2]
    2662 Thread_13693   DispatchQueue_6: com.apple.root.background-qos  (concurrent)
    + 2662 start_wqthread  (in libsystem_pthread.dylib) + 15 [0x7fff634ce827]
    +   2662 _pthread_wqthread  (in libsystem_pthread.dylib) + 220  [0x7fff634cf6b6]
    +     2662 _dispatch_worker_thread2  (in libdispatch.dylib) + 92  [0x7fff63283f22]
    +       2662 _dispatch_root_queue_drain  (in libdispatch.dylib) + 663  [0x7fff63283933]
    +         2662 _dispatch_client_callout  (in libdispatch.dylib) + 8  [0x7fff6327550e]
    +           2662 _dispatch_call_block_and_release  (in libdispatch.dylib) + 12  [0x7fff63274583]
    +             2662 ???  (in myApp)  load address 0x1086d0000 + 0xa3169  [0x108773169]
    +               2662 ???  (in myApp)  load address 0x1086d0000 + 0x446aa  [0x1087146aa]
    +                 2662 ???  (in myApp)  load address 0x1086d0000 + 0x46533  [0x108716533]
    +                   2662 ???  (in myApp)  load address 0x1086d0000 + 0x4a3d9  [0x10871a3d9]
    +                     2662 ???  (in myApp)  load address 0x1086d0000 + 0x4a3d9  [0x10871a3d9]
    +                       2662 ???  (in myApp)  load address 0x1086d0000 + 0x4a3d9  [0x10871a3d9]
    +                         2662 ???  (in myApp)  load address 0x1086d0000 + 0x4a3d9  [0x10871a3d9]
    +                           2662 ???  (in myApp)  load address 0x1086d0000 + 0x4a3d9  [0x10871a3d9]
    +                             2662 ???  (in myApp)  load address 0x1086d0000 + 0x4a3d9  [0x10871a3d9]
    +                               2662 ???  (in myApp)  load address 0x1086d0000 + 0x4a3be  [0x10871a3be]
    +                                 2662 URL.appendingPathComponent(_:)  (in libswiftFoundation.dylib) + 61  [0x7fff62e1e3ad]
    +                                   2662 -[NSURL(NSURLPathUtilities) URLByAppendingPathComponent:]  (in Foundation) + 217  [0x7fff2e2e843a]
    +                                     2662 -[NSURL getResourceValue:forKey:error:]  (in CoreFoundation) + 110 [0x7fff2bc5d4ff]
    +                                       2662 CFURLCopyResourcePropertyForKey  (in CoreFoundation) + 119 [0x7fff2bc46958]
    +                                         2662 _FSURLCopyResourcePropertyForKeyInternal(__CFURL const*, __CFString const*, void*, void*, __CFError**, unsigned char)  (in CoreServicesInternal) + 221  [0x7fff4472feba]
    +                                           2662 prepareValuesForBitmap(__CFURL const*, __FileCache*, _FilePropertyBitmap*, __CFError**)  (in CoreServicesInternal) + 363  [0x7fff447337e4]
    +                                             2662 corePropertyProviderPrepareValues(__CFURL const*, __FileCache*, __CFString const* const*, void const**, long, void const*, __CFError**)  (in CoreServicesInternal) + 631  [0x7fff44733ac4]
    +                                               2662 __getattrlist  (in libsystem_kernel.dylib) + 10  [0x7fff6340fad2]
    2662 Thread_13846: com.apple.NSEventThread
    + 2662 thread_start  (in libsystem_pthread.dylib) + 15 [0x7fff634ce83b]
    +   2662 _pthread_start  (in libsystem_pthread.dylib) + 148 [0x7fff634d2e65]
    +     2662 _NSEventThread  (in AppKit) + 132  [0x7fff28fdca72]
    +       2662 CFRunLoopRunSpecific  (in CoreFoundation) + 499 [0x7fff2bc71bd3]
    +         2662 __CFRunLoopRun  (in CoreFoundation) + 1695 [0x7fff2bc728e7]
    +           2662 __CFRunLoopServiceMachPort  (in CoreFoundation) + 322  [0x7fff2bc73d0b]
    +             2662 mach_msg  (in libsystem_kernel.dylib) + 60 [0x7fff6340f5d0]
    +               2662 mach_msg_trap  (in libsystem_kernel.dylib) + 10  [0x7fff6340f25a]
    2662 Thread_59695   DispatchQueue_158: com.apple.CFVolumeObserver.0x600003dbf8a0  (serial)
    + 2662 start_wqthread  (in libsystem_pthread.dylib) + 15 [0x7fff634ce827]
    +   2662 _pthread_wqthread  (in libsystem_pthread.dylib) + 290  [0x7fff634cf6fc]
    +     2662 _dispatch_workloop_worker_thread  (in libdispatch.dylib) + 598  [0x7fff63284a9e]
    +       2662 _dispatch_lane_invoke  (in libdispatch.dylib) + 363  [0x7fff6327b452]
    +         2662 _dispatch_lane_serial_drain  (in libdispatch.dylib) + 263  [0x7fff6327a980]
    +           2662 _dispatch_source_invoke  (in libdispatch.dylib) + 2084  [0x7fff632873c4]
    +             2662 _dispatch_continuation_pop  (in libdispatch.dylib) + 414  [0x7fff632776c0]
    +               2662 _dispatch_client_callout  (in libdispatch.dylib) + 8  [0x7fff6327550e]
    +                 2662 __DASessionSetDispatchQueue_block_invoke_2  (in DiskArbitration) + 56  [0x7fff2df7de66]
    +                   2662 _DASessionCallback  (in DiskArbitration) + 259  [0x7fff2df7df70]
    +                     2662 _DADispatchCallback  (in DiskArbitration) + 198  [0x7fff2df7e254]
    +                       2662 _VolumeObserverDiskUnmountApprovalCallback  (in CoreFoundation) + 159  [0x7fff2bd5d738]
    +                         2662 __createVolumeObserverSubsystem_block_invoke  (in AppKit) + 992 [0x7fff291110ea]
    +                           2662 _dispatch_semaphore_wait_slow  (in libdispatch.dylib) + 98 [0x7fff63275e6a]
    +                             2662 _dispatch_sema4_wait  (in libdispatch.dylib) + 16  [0x7fff6327599d]
    +                               2662 semaphore_wait_trap  (in libsystem_kernel.dylib) + 10  [0x7fff6340f296]
    2662 Thread_233483
      2662 start_wqthread  (in libsystem_pthread.dylib) + 15 [0x7fff634ce827]
        2662 _pthread_wqthread  (in libsystem_pthread.dylib) + 390  [0x7fff634cf760]
          2662 __workq_kernreturn  (in libsystem_kernel.dylib) + 10  [0x7fff6341092e]

Replies

HIToolbox?


It always helps to add your IDE working/testing details, thanks.