FileProvider Daemon hangs when NSFileProviderManager.add is call twice within one second

FileProvider Daemon (fileproviderd) hangs when NSFileProviderManager.add is called twice within one second.

A lot of threads are block in libobjc.A.dylib objc_sync_enter + 27. And a thread is blocked in _dispatch_sync_f_slow. It looks like a deadlock.

thread #1, queue = 'com.apple.main-thread'
    frame #0: 0x00007ff818d170ea libsystem_kernel.dylib`__ulock_wait + 10
    frame #1: 0x00007ff818d6627e libsystem_platform.dylib`_os_unfair_lock_lock_slow + 155
    frame #2: 0x00007ff818bed412 libobjc.A.dylib`objc_sync_enter + 27
    frame #3: 0x00007ff92b915418 FileProviderDaemon`-[FPDExtensionManager forceSynchronousProviderUpdate] + 32
    frame #4: 0x00007ff92b91539a FileProviderDaemon`-[FPDExtensionManager accountsChanged] + 312
    frame #5: 0x00007ff818e0e75c CoreFoundation`__CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
    frame #6: 0x00007ff818eabb32 CoreFoundation`___CFXRegistrationPost_block_invoke + 49


thread #2, queue = 'com.ABCDE.FGHIJ.FileProvider.domain'
    frame #0: 0x00007ff818d170a2 libsystem_kernel.dylib`kevent_id + 10
    frame #1: 0x00007ff818bb9c38 libdispatch.dylib`_dispatch_kq_poll + 164
    frame #2: 0x00007ff818bba6c9 libdispatch.dylib`_dispatch_event_loop_wait_for_ownership + 521
    frame #3: 0x00007ff818ba8a3b libdispatch.dylib`__DISPATCH_WAIT_FOR_QUEUE__ + 279
  * frame #4: 0x00007ff818ba8696 libdispatch.dylib`_dispatch_sync_f_slow + 170
    frame #5: 0x00007ff92b8e063e FileProviderDaemon`__106-[FPDProvider addDomain:byImportingDirectoryAtURL:unableToStartup:reloadDomain:request:completionHandler:]_block_invoke + 2977
    frame #6: 0x00007ff82b4257d7 FileProvider`__fp_dispatch_async_with_logs_block_invoke + 87

...

macOS 12.6

Note:

Hi,

We are facing the same problem in our product test builds. Application just timeouts on trying to register file provider domain. fileproviderd just stuck and never released until it killed. Stack traces shows quite obvious deadlock. It seems that it appear after upgrade to the latest monterey 12.6.

  Thread 0x3e02c5    DispatchQueue "com.ProductName.FileProviderPlugin.domain"(108)    1000 samples (1-1000)    priority 37 (base 37)
  1000  start_wqthread + 15 (libsystem_pthread.dylib + 8023) [0x7ff80f727f57]
    1000  _pthread_wqthread + 326 (libsystem_pthread.dylib + 12240) [0x7ff80f728fd0]
      1000  _dispatch_workloop_worker_thread + 753 (libdispatch.dylib + 81646) [0x7ff80f585eee]
        1000  _dispatch_lane_invoke + 417 (libdispatch.dylib + 40496) [0x7ff80f57be30]
          1000  _dispatch_lane_serial_drain + 672 (libdispatch.dylib + 37655) [0x7ff80f57b317]
            1000  _dispatch_client_callout + 8 (libdispatch.dylib + 13079) [0x7ff80f575317]
              1000  _dispatch_call_block_and_release + 12 (libdispatch.dylib + 8396) [0x7ff80f5740cc]
                1000  __fp_dispatch_async_with_logs_block_invoke + 87 (FileProvider + 1062871) [0x7ff821dff7d7]
                  1000  __106-[FPDProvider addDomain:byImportingDirectoryAtURL:unableToStartup:reloadDomain:request:completionHandler:]_block_invoke + 2977 (FileProviderDaemon + 337470) [0x7ff9222ba63e]
                    1000  _dispatch_sync_f_slow + 170 (libdispatch.dylib + 67222) [0x7ff80f582696]
                      1000  __DISPATCH_WAIT_FOR_QUEUE__ + 279 (libdispatch.dylib + 68155) [0x7ff80f582a3b]
                        1000  _dispatch_event_loop_wait_for_ownership + 521 (libdispatch.dylib + 141001) [0x7ff80f5946c9]
                          1000  kevent_id + 10 (libsystem_kernel.dylib + 12450) [0x7ff80f6f10a2]
                           *1000  ??? (kernel + 6404576) [0xffffff800082b9e0] (blocked by turnstile waiting for fileproviderd [75086] thread 0x3e0272)
                           
  Thread 0x3e0272    DispatchQueue "extension session queue for com.ProductName.FileProviderPlugin"(107)    1000 samples (1-1000)    priority 37 (base 37)
  1000  start_wqthread + 15 (libsystem_pthread.dylib + 8023) [0x7ff80f727f57]
    1000  _pthread_wqthread + 326 (libsystem_pthread.dylib + 12240) [0x7ff80f728fd0]
      1000  _dispatch_workloop_worker_thread + 753 (libdispatch.dylib + 81646) [0x7ff80f585eee]
        1000  _dispatch_lane_invoke + 417 (libdispatch.dylib + 40496) [0x7ff80f57be30]
          1000  _dispatch_lane_serial_drain + 672 (libdispatch.dylib + 37655) [0x7ff80f57b317]
            1000  _dispatch_client_callout + 8 (libdispatch.dylib + 13079) [0x7ff80f575317]
              1000  _dispatch_call_block_and_release + 12 (libdispatch.dylib + 8396) [0x7ff80f5740cc]
                1000  __fp_dispatch_async_with_logs_block_invoke + 87 (FileProvider + 1062871) [0x7ff821dff7d7]
                  1000  __63-[FPDDomain _startObservingRootAndResumeIndexerWithCompletion:]_block_invoke + 142 (FileProviderDaemon + 240056) [0x7ff9222a29b8]
                    1000  ??? (fileproviderd + 1569896) [0x104190468]
                      1000  OS_dispatch_queue.sync<A>(execute:) + 123 (libswiftDispatch.dylib + 28075) [0x7ff82231fdab]
                        1000  OS_dispatch_queue._syncHelper<A>(fn:execute:rescue:) + 267 (libswiftDispatch.dylib + 26667) [0x7ff82231f82b]
                          1000  partial apply for implicit closure #2 in implicit closure #1 in OS_dispatch_queue.sync<A>(execute:) + 34 (libswiftDispatch.dylib + 30418) [0x7ff8223206d2]
                            1000  implicit closure #2 in implicit closure #1 in OS_dispatch_queue.sync<A>(execute:) + 148 (libswiftDispatch.dylib + 29076) [0x7ff822320194]
                              1000  _dispatch_lane_barrier_sync_invoke_and_complete + 60 (libdispatch.dylib + 67566) [0x7ff80f5827ee]
                                1000  _dispatch_client_callout + 8 (libdispatch.dylib + 13079) [0x7ff80f575317]
                                  1000  thunk for @escaping @callee_guaranteed () -> () + 14 (libswiftDispatch.dylib + 10398) [0x7ff82231b89e]
                                    1000  partial apply for thunk for @callee_guaranteed () -> () + 17 (libswiftDispatch.dylib + 32097) [0x7ff822320d61]
                                      1000  closure #1 in closure #1 in OS_dispatch_queue._syncHelper<A>(fn:execute:rescue:) + 88 (libswiftDispatch.dylib + 26952) [0x7ff82231f948]
                                        1000  thunk for @callee_guaranteed () -> (@out A, @error @owned Error)partial apply + 9 (libswiftDispatch.dylib + 33033) [0x7ff822321109]
                                          1000  partial apply for thunk for @callee_guaranteed () -> (@out A, @error @owned Error) + 17 (libswiftDispatch.dylib + 32417) [0x7ff822320ea1]
                                            1000  ??? (fileproviderd + 1902745) [0x1041e1899]
                                              1000  ??? (fileproviderd + 1831844) [0x1041d03a4]
                                                1000  ??? (fileproviderd + 1569647) [0x10419036f]
                                                  1000  ??? (fileproviderd + 1560911) [0x10418e14f]
                                                    1000  ??? (fileproviderd + 1550720) [0x10418b980]
                                                      1000  -[FPDExtensionSession newFileProviderProxyWithTimeout:pid:createIfNeeded:] + 152 (FileProviderDaemon + 642916) [0x7ff922304f64]
                                                        1000  _dispatch_lane_barrier_sync_invoke_and_complete + 60 (libdispatch.dylib + 67566) [0x7ff80f5827ee]
                                                          1000  _dispatch_client_callout + 8 (libdispatch.dylib + 13079) [0x7ff80f575317]
                                                            1000  __74-[FPDExtensionSession newFileProviderProxyWithTimeout:pid:createIfNeeded:]_block_invoke + 279 (FileProviderDaemon + 643249) [0x7ff9223050b1]
                                                              1000  -[FPDExtensionSession _connectionWithError:] + 1129 (FileProviderDaemon + 639564) [0x7ff92230424c]
                                                                1000  -[FPDProvider providerDomainForDomain:] + 54 (FileProviderDaemon + 316668) [0x7ff9222b54fc]
                                                                  1000  objc_sync_enter + 27 (libobjc.A.dylib + 58386) [0x7ff80f5c7412]
                                                                    1000  __ulock_wait + 10 (libsystem_kernel.dylib + 12522) [0x7ff80f6f10ea]
                                                                     *1000  ??? (kernel + 6814208) [0xffffff800088fa00] (blocked by turnstile waiting for fileproviderd [75086] thread 0x3e02c5)

Thanks for the report. This was fixed in macOS 13. Let us know if you see the issue on macOS 13 or later.

FileProvider Daemon hangs when NSFileProviderManager.add is call twice within one second
 
 
Q