Deadlock on second creation of CPNavigationSession

Originator:Yury.Lapitsky
Number:rdar://48196961 Date Originated:19.02.2019
Status:Open Resolved:
Product:CarPlay Product Version:iOS 12.1
Classification:Bug Reproducible:100%
 
Summary:
Accidental retaining CPNavigationSession without cancelling or finishing produces a deadlock on the next session creation. Such behavior isn’t obvious when a developer hasn’t found yet the issue related to the memory management of the first retained session. 

Steps to Reproduce:
1. Create a CPNavigationSession and retain it (for example in property)
2. Create another CPNavigationSession without canceling, finishing or releasing 1st.

In the sample project:

1. Press Plan route
2. In the Preview dialog press Launch button
3. Repeat 1-2 

Expected Results:
An exception or another way to notify that previous session is still active

Actual Results:
Dead lock on [CPMapTemplate startNavigationSessionForTrip:]. The stacktrace:

* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
  * frame #0: 0x000000010f70b1b6 libsystem_kernel.dylib`semaphore_wait_trap + 10
    frame #1: 0x000000010f371cb8 libdispatch.dylib`_dispatch_sema4_wait + 16
    frame #2: 0x000000010f3724c9 libdispatch.dylib`_dispatch_semaphore_wait_slow + 101
    frame #3: 0x0000000108880e92 CarPlay`-[CPMapTemplate startNavigationSessionForTrip:] + 329
    frame #4: 0x0000000108534fa0 CountryRoads`TemplateManager.createNavigationSession(trip=0x0000600003417630, mapTemplate=0x000060000085d4d0, self=0x0000600000d40210) at TemplateManager.swift:156
    frame #5: 0x00000001085376c9 CountryRoads`TemplateManager.mapTemplate(mapTemplate=0x000060000085d4d0, trip=0x0000600003417630, routeChoice=0x00006000034174b0, self=0x0000600000d40210) at TemplateManager.swift:162
    frame #6: 0x0000000108537806 CountryRoads`@objc TemplateManager.mapTemplate(_:startedTrip:using:) at <compiler-generated>:0
    frame #7: 0x0000000108882d75 CarPlay`__58-[CPMapTemplate startTripIdentifier:usingRouteIdentifier:]_block_invoke_2 + 96
    frame #8: 0x00000001088826b0 CarPlay`-[CPMapTemplate _resolveTrip:routeChoice:completion:] + 534
    frame #9: 0x0000000108882cf4 CarPlay`__58-[CPMapTemplate startTripIdentifier:usingRouteIdentifier:]_block_invoke + 147
    frame #10: 0x000000010f370595 libdispatch.dylib`_dispatch_call_block_and_release + 12
    frame #11: 0x000000010f371602 libdispatch.dylib`_dispatch_client_callout + 8
    frame #12: 0x000000010f37e99a libdispatch.dylib`_dispatch_main_queue_callback_4CF + 1541
    frame #13: 0x000000010d9603e9 CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    frame #14: 0x000000010d95aa76 CoreFoundation`__CFRunLoopRun + 2342
    frame #15: 0x000000010d959e11 CoreFoundation`CFRunLoopRunSpecific + 625
    frame #16: 0x0000000112edb1dd GraphicsServices`GSEventRunModal + 62
    frame #17: 0x000000010b5e181d UIKitCore`UIApplicationMain + 140
    frame #18: 0x0000000108545857 CountryRoads`main at AppDelegate.swift:13
    frame #19: 0x000000010f3e7575 libdyld.dylib`start + 1

Version:
12.1

Notes:
Additional mentioning in the documentation of existing limitation is also missing.

Configuration:

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!