AsyncRenderer causes crashes in ForEach when in Swift 6 language mode

Hi!

We've recently done a big migration to Swift 6 language mode in our app and are now getting reports of crashes occurring due to closures in our SwiftUI code (most often the view builder in ForEach) not running on the main queue but instead running on the queue com.apple.SwiftUI.AsyncRenderer. One example of a call stack (ScheduleListView is our view that is in Swift 6 mode):

Thread 16
#0	(null) in _dispatch_assert_queue_fail ()
#1	(null) in dispatch_assert_queue$V2.cold.1 ()
#2	(null) in dispatch_assert_queue ()
#3	(null) in swift_task_isCurrentExecutorWithFlagsImpl(swift::SerialExecutorRef, swift::swift_task_is_current_executor_flag) ()
#4	(null) in closure #2 in closure #1 in closure #1 in ScheduleListView.body.getter ()
#5	(null) in closure #1 in ForEachState.item(at:offset:) ()
#6	(null) in partial apply for closure #1 in ForEachState.item(at:offset:) ()
#8	(null) in partial apply for closure #1 in _withObservation<A>(do:) ()
....

(We have many other crashes with similar crash reports but in other views)

Has anybody else run into something similar? Is there anything (other than simply reverting to Swift 5 mode again) that we can do to fix or at least reduce the amount of crashes? We're having a hard time finding anything out of the ordinary that we're doing in our views.

Regards

Answered by DTS Engineer in 860776022

Could you open a bug report, include the symbolicated crash report and post the FB number here once you do. Bug Reporting: How and Why? has tips on creating your bug report.

Could you open a bug report, include the symbolicated crash report and post the FB number here once you do. Bug Reporting: How and Why? has tips on creating your bug report.

Thank you!

We've now submitted a bug report (FB20692404).

Hey. Having the same issue. We are accessing a MainActor Observable model object from the body, and somehow this being executed off the main thread and throwing the error

com.apple.SwiftUI.AsyncRenderer: EXC_BREAKPOINT (code=1, subcode=0x100ecaf18) "%sBlock was %sexpected to execute on queue [%s (%p)]"

public var body: some View {
        ForEach(model.items) { item in
            content(item)
        }
}

I am experiencing a regression on this with iOS 27.0. The same app works fine with iOS 26.6+ but sometimes crashes on iOS 27 with the SwiftUI.AsyncRenderer while being isolated to main.

Anyone else having the same issue?

Hello @MacSwifter,

From what I can see, the original report shared above (FB20692404) is still open and under investigation.

If you are experiencing the same issue, we would like to collect more information from you. Please file a bug report through Feedback Assistant. Attach your sample project and steps to reproduce the issue.

Once complete, reply with the FB number. I will relate this report to the original report so the relevant teams investigating the issue have a timeline for the issue.

It seems like this issue is effecting some, not others and we would like more information about your environment to help us in our investigation.

In your report, include the software and hardware versions used in testing, as well as the version of Xcode and MacOS used when building.

If this issue is not related, I can take a look for workarounds or share your report with a more appropriate team if needed.

Status updates will be provided through Feedback Assistant, these reports are between you and Apple's teams, so you won't be able to see updates on the original report – it's best you file your own.

Thank you.

 Travis

I have the same issue, com.apple.SwiftUI.AsyncRenderer is crashing on _dispatch_assert_queue_fail. There is no my code in the stack trace except the MyApp.body.getter method. I filed FB24722147 two weeks ago, still no reply. Please help!

AsyncRenderer causes crashes in ForEach when in Swift 6 language mode
 
 
Q