I've also been struggling to solve this issue and frankly even to recreate the hang consistently. Instruments can capture the hang but it always ends in a similar mach_msg2_trap.
I am using the AnimationTool to add a few CATextLayers on top of my videos - and haven't even thought to trace the issue there. I use it below:
videoComposition.animationTool = AVVideoCompositionCoreAnimationTool(postProcessingAsVideoLayer: videoLayer, in: parentLayer)
This is part of a video compilation pipeline that's running in a background thread.
Here's an example thread backtrace when the app is in a hung state:
thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
frame #0: 0x00000001ed345178 libsystem_kernel.dylibmach_msg2_trap + 8 frame #1: 0x00000001ed344f10 libsystem_kernel.dylibmach_msg2_internal + 80
frame #2: 0x00000001ed344e28 libsystem_kernel.dylibmach_msg_overwrite + 436 frame #3: 0x00000001ed344c68 libsystem_kernel.dylibmach_msg + 24
frame #4: 0x00000001a7245f04 QuartzCoreCA::Render::Message::send_message() + 84 frame #5: 0x00000001a72108c4 QuartzCoreCA::Render::Encoder::send_message(unsigned int, unsigned int, unsigned int*, unsigned long) + 868
frame #6: 0x00000001a7255d64 QuartzCoreCA::Context::commit_transaction(CA::Transaction*, double, double*) + 14036 frame #7: 0x00000001a724bb80 QuartzCoreCA::Transaction::commit() + 648
frame #8: 0x00000001a724b828 QuartzCoreCA::Transaction::flush_as_runloop_observer(bool) + 88 frame #9: 0x00000001a7eb1f34 UIKitCore_UIApplicationFlushCATransaction + 52
frame #10: 0x00000001a7eb1a4c UIKitCore_UIUpdateSequenceRun + 84 frame #11: 0x00000001a7eb113c UIKitCoreschedulerStepScheduledMainSection + 144
frame #12: 0x00000001a7eb11f8 UIKitCorerunloopSourceCallback + 92 frame #13: 0x00000001a5c110ac CoreFoundationCFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 28
frame #14: 0x00000001a5c10328 CoreFoundation__CFRunLoopDoSource0 + 176 frame #15: 0x00000001a5c0eadc CoreFoundation__CFRunLoopDoSources0 + 244
frame #16: 0x00000001a5c0d818 CoreFoundation__CFRunLoopRun + 828 frame #17: 0x00000001a5c0d3f8 CoreFoundationCFRunLoopRunSpecific + 608
frame #18: 0x00000001e919b4f8 GraphicsServicesGSEventRunModal + 164 frame #19: 0x00000001a80338a0 UIKitCore-[UIApplication _run] + 888
frame #20: 0x00000001a8032edc UIKitCoreUIApplicationMain + 340 frame #21: 0x00000001aaa44898 SwiftUI___lldb_unnamed_symbol172585 + 176
frame #22: 0x00000001aaa446dc SwiftUI___lldb_unnamed_symbol172583 + 152 frame #23: 0x00000001aa6b525c SwiftUI___lldb_unnamed_symbol143448 + 128
frame #24: 0x0000000103216690 appstatic MainApp.$main(self=app.MainApp) at <compiler-generated>:0 frame #25: 0x0000000103216740 appmain at MainApp.swift:17:8
frame #26: 0x00000001c8962dcc dyld`start + 2240
Has anyone found an alternate method for adding text overlays to videos? When disabling the AnimationTool layer I haven't been able to get it to crash - but those layers are pretty important to our app =).
Thank you for finding this issue - I was going crazy tracking it down. But now I need to find a work-around!