Stopping replicator locks the "CouchbaseLite" thread

I’m making large refactoring in my app (iOS) to make all CBL staff in background thread. I have chosen for this purpose “manager.backgroundTellDatabaseNamed” because it looks easer than manually creating Thread. The only one place I do something in main thread is creating Manager. All other things on background including replicator start and stop functions. But when I call stop() for continuous replication that is running the CouchbaseLite thread is locked. Here’s stacktrace:

* thread #41, name = 'CouchbaseLite'
    frame #0: 0x000000011c2ecbf2 libsystem_kernel.dylib`__psynch_cvwait + 10
    frame #1: 0x000000011c322833 libsystem_pthread.dylib`_pthread_cond_wait + 769
    frame #2: 0x0000000112f65cea Foundation`-[NSCondition waitUntilDate:] + 143
    frame #3: 0x0000000112f65c19 Foundation`-[NSConditionLock lockWhenCondition:beforeDate:] + 91
  * frame #4: 0x0000000112b1375c CouchbaseLite`-[CBL_RunLoopServer waitForDatabaseManager:](self=0x000060400082bba0, _cmd=<unavailable>, block=<unavailable>) at CBL_Server.m:237 [opt]
    frame #5: 0x0000000112b6cbdc CouchbaseLite`-[CBLReplication tellReplicatorAndWait:](self=0x00006040003894b0, _cmd=<unavailable>, block=<unavailable>) at CBLReplication.m:572 [opt]
    frame #6: 0x0000000112b6b7e9 CouchbaseLite`-[CBLReplication stop](self=<unavailable>, _cmd=<unavailable>) at CBLReplication.m:319 [opt]

Why does it happen?

manager.backgroundTellDatabaseNamed runs your block on the same background thread that’s used by the replicator and by LiveQueries. Don’t overuse it, and don’t use it for replication calls.

If you want to move CBL code off of the main thread, then just

  • Create a new serial dispatch queue
  • Create a new CBLManager
  • Set the manager’s dispatchQueue to the queue you created
  • Do your CBL calls inside dispatch_async calls on your queue.

Thanks so much for reply! I didn’t now about this approach.