swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.59k stars 10.37k forks source link

Error in LocalTestingDistributedActorSystem.assignID #63679

Open dimsumthinking opened 1 year ago

dimsumthinking commented 1 year ago

Description I'm getting a crash when I create a distributed actor and pass in LocalTestingDistributedActorSystem() as the actor system. I do not see this crash when I tried to create a minimal version of this app to accompany this report so it is likely a problem in my code and not LocalTestingDistributedActorSystem - but I figured it's safer to submit it so you can see it.

Steps to reproduce Please look at the code in this project:https://github.com/editorscut/ec013async/tree/main/TempFilesForBugReport/CrashingExample/AppIcons

In Controllers/AppStore I create an instance of the distributed actor Searcher and pass in LocalTestingDistributedActorSystem() as the Actor System.

The app crashes if in the init in Searcher I set self.actorSystem = actorSystem (the passed in value) but does not crash if I ignore the passed in value and set self.actorSystem = LocalTestingDistributedActorSystem() (i.e. a newly created instance).

The backtrace shows an os_unfair_lock_corruption_abort that seems to come from LocalTestingDistributedActorSystem.assignID.

As a contrast, I've created a minimal version of this app that creates a distributed actor in the same way and it seems to work fine. The minimal example is https://github.com/editorscut/ec013async/tree/main/TempFilesForBugReport/MinimalExampleForBugReport

Noting that the backtrace shows the problem occurs on the main thread, I found that if I move the creation of the distributed actor off of the main actor that I don't see the crash. https://github.com/editorscut/ec013async/tree/main/TempFilesForBugReport/OffMainActor/AppIcons

Expected behavior I would expect to be able to pass in the actor system

Environment I'm using Xcode 14.2 targeting iOS 16.2.

ktoso commented 1 year ago

Thanks for the report, will look into it. I wonder if it’s a lifetime issue in SIL that we saw regress elsewhere…

ktoso commented 1 year ago

rdar://105531823

dimsumthinking commented 1 year ago

I don't know the protocol - will there be any update on progress here? Selfishly, I'd love to know if/when I can remove the workaround from my book.