I'm currently having production crashes reported by Firebase pointing to some auto-layout work being done on a background thread. While the fix would be obviously wrapping the offending code on a dispatch main block, we can't find anything pointing to that code.
This scenario seems particularly hard to reproduce - we haven't been able to reproduce it in development.
The crash seems to happen during / after launch, and it varies a little from user to user, which could mean some async work triggering it based on the variance. I checked all the threads provided by the stack trace and couldn't find anything meaningful.
This is the stack trace provided by Firebase - absolutely no mention of app code triggering that update. Wondering if anyone may have some insight.
Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.
Thread that crashes
Fatal Exception: NSInternalInconsistencyException
0 CoreFoundation 0x9270c __exceptionPreprocess
1 libobjc.A.dylib 0x14f04 objc_exception_throw
2 CoreAutoLayout 0x5000 -[NSISEngine withAutomaticOptimizationDisabled:]
3 CoreAutoLayout 0x9e00 -[NSISEngine _optimizeWithoutRebuilding]
4 CoreAutoLayout 0xbd2c -[NSISEngine optimize]
5 CoreAutoLayout 0x49b4 -[NSISEngine performPendingChangeNotifications]
6 UIKitCore 0x3331a0 -[UIView(Hierarchy) layoutSubviews]
7 UIKitCore 0x17c738 -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
8 QuartzCore 0x3cedc CA::Layer::layout_if_needed(CA::Transaction*)
9 QuartzCore 0x2fc90 CA::Layer::layout_and_display_if_needed(CA::Transaction*)
10 QuartzCore 0x4367c CA::Context::commit_transaction(CA::Transaction*, double, double*)
11 QuartzCore 0x4c164 CA::Transaction::commit()
12 QuartzCore 0x9fa08 CA::Transaction::release_thread(void*)
13 libsystem_pthread.dylib 0x3da0 _pthread_tsd_cleanup
14 libsystem_pthread.dylib 0x6c18 _pthread_exit
15 libsystem_pthread.dylib 0x225c pthread_main_np
16 libsystem_pthread.dylib 0x1e98 _pthread_wqthread
17 libsystem_pthread.dylib 0x193c start_wqthread
Main thread trace
com.apple.main-thread
0 libsystem_kernel.dylib 0x14e0 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x1b24 mach_msg + 76
2 CoreFoundation 0x7820 __CFRunLoopServiceMachPort + 372
3 CoreFoundation 0xbcac __CFRunLoopRun + 1180
4 CoreFoundation 0x1f6b8 CFRunLoopRunSpecific + 600
5 GraphicsServices 0x1374 GSEventRunModal + 164
6 UIKitCore 0x513e88 -[UIApplication _run] + 1100
7 UIKitCore 0x2955ec UIApplicationMain + 364
8 MyApp 0x671c main + 20 (main.swift:20)
9 ??? 0x102689ce4 (Missing)