Apps running in Xcode 13 beta 5 iOS simulator crash shortly after a DispatchSemaphore is released by the system

Filed as FB9486500

Once a local DispatchSemaphore is released by the system, the app crashes in the Xcode 13 beta 5 simulator, but works correctly on the device running iOS 15 beta 5. This is very simple to reproduce.

E.g. adding this on a boilerplate Xcode beta 5 project's VC:

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    let semaphore = DispatchSemaphore(value: 0)
    // If this was a strong instance property the crash does not occur

    DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
        semaphore.signal()
    }

    DispatchQueue.global().async {
        print("Waiting on semaphore...")
        semaphore.wait()
        print("Semaphore has been signalled, iOS sim will crash about 10 seconds after this message, device will be fine.")
    }
}

This issue occurs only on the sim, not a device, on iOS 15 beta 5. In case it's relevant, running on an M1 Mac.

The most critical API affected by this so far is NSFileCoordinator, which totally breaks in the sim when it internally tries to handle semaphores.

The same issue with RunLoop:

RunLoop.current.run(mode: RunLoop.Mode.default, before: Date.distantFuture)

Crash only on iOS 15 beta 5 on the simulator.

From the iOS 15 beta 8 notes, this may help:

Using dispatch semaphores in an iOS app running in a device simulator on a Mac with Apple silicon running macOS 11 will cause the app to crash. (81783378)

Workaround: In Xcode, select Product > Scheme > Edit Scheme, then deselect Run > Options > Queue Debugging > "Enable backtrace recording."

Apps running in Xcode 13 beta 5 iOS simulator crash shortly after a DispatchSemaphore is released by the system
 
 
Q