Crash in AVPlayerLayer KVO code, showing Swift 4.0's internal KVO machinery at the top of the stack

Number:rdar://36663633 Date Originated:19-Jan-2018 10:47 AM
Status:Open Resolved:
Product:iOS + SDK Product Version:11
Classification:Crash/Hang/Data Loss Reproducible:Sometimes
We just released an update to our app compiled with the Swift 4 compiler (Xcode 9.2, all code in Swift 3.2 mode) for the first time, and we started seeing crashes in code that uses the AVPlayerLayer API, which didn’t change at all in this release. The only thing that changed is we switched from Xcode 8.3.3 (Swift 3) to Xcode 9.2 (Swift 4), which introduced the new Swift KVO API.

Upon further analysis, we noticed that in all the crashes, the main thread is always blocked on a mutex adding a Swift 4 KVO observer to something else. On this release we did start using the new Swift 4 syntax for KVO (just not on any AVFoundation code)

Steps to Reproduce:
We don’t have specific retro steps to hit this. It doesn’t happen continuously, but with our volume of users it’s enough to see hundreds of crashes after less than 24h with the build out in the AppStore.

Expected Results:
App doesn’t crash when using the Swift KVO API in an unrelated location.

Actual Results:
We get crashes in AVPlayerLayer’s internal KVO code when we started using the Swift 4 compiler and the new KVO syntax.


See attached screenshot for crash logs.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at 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!