-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-14875] Resuming continuations from actor contexts can hang #57222
Comments
Confirmed. For reference, here's my report: https://bugs.swift.org/browse/SR-14841 |
Not sure if this totally a dupe of the previously raised issue as the scenario I encountered was non-deterministic but if it isn’t a dupe they certainly seem closely related. |
@swift-ci create |
I've created a simplified test case so the issue should be clearer and if it is me misunderstanding what is meant to happen that should also be visible. This works most of the time 90 runs out of 100 or 95 times out 100 with the commented lines in the pause method uncommented (which I think shouldn't be necessary but that does depend on the withCheckedContinuation being immediately executed. When I repeated the test with a class instead of an actor I did also get some errors with this case but that is possibly to be expected to be somewhat racy (hence the wish to use an actor in this situation). This is tested against the 5.5 Development Snapshot 2021-07-08(a) on an M1 Mac mini running Monterey beta2. Xcode beta 2. The test is within the tests for a package and I'm using the Run repeatedly options. import XCTest
@available(iOS 15.0, macOS 12.0, *)
actor SUTActor {
var continuation: CheckedContinuation<(),Never>?
var canGo = false
func pause() async {
if canGo { return }
await withCheckedContinuation { (continuation: CheckedContinuation<Void, Never>) -> Void in
// if canGo {
// continuation.resume(returning: ())
// } else {
self.continuation = continuation
// }
}
}
func go() {
canGo = true
continuation?.resume()
}
}
@available(iOS 15.0, macOS 12.0, *)
final class ActorContinuationTests : XCTestCase {
func testPauseGo() {
let sut = SUTActor()
let exp = expectation(description: "Will resume")
Task.detached(priority: .high) {
await sut.pause()
exp.fulfill()
}
Task.detached(priority: .default) {
await sut.go()
}
waitForExpectations(timeout: 0.5, handler: nil)
_ = sut // Ensure lifetime sufficient
}
} |
This is still happening in beta 3 (Xcode and macOS Monterey). I'm also seeing it (although less frequently in the iOS Simulator in Xcode beta3). All tested on M1 Mac only. This feels fairly critical to me I'm going to try to raise it on the Swift forums to see if I can get some attention for it. |
From what I can tell, the example with `SUTActor` should work if you do not explicitly specify the priorities and are using macOS 12 beta 3 (or using a recent toolchain snapshot), which should include this patch: #37939 Can you confirm if that's the case? |
This is the same issue as SR-14802, I'll add more details there in a bit. |
Attachment: Download
Environment
Xcode 13 beta 2. Snapshot builds 5.5 toolchain 2021-07-03, 2021-07-01, 2021-06-29, M1 Mac mini, Monterey beta2, Xcode beta 3, Monterey beta 3
Additional Detail from JIRA
md5: 0f377d3ebb1ee24957d4228c49aeb885
duplicates:
relates to:
Issue Description:
Note also separate hang report here: SR-14802
I've been playing with and testing creating my own AsyncSequences. The first implementation below works well, the second is highly unreliable. The only difference is that the first one returns the continuation from the actor which then gets resumed and the second one it is resumed from the actor context.
I'm not aware of anything in the specification about not firing continuations from actor context. If it really shouldn't be done there should be compile time errors if there is an attempt to resume a continuation from an actor context.
To reproduce open the package in Xcode and run the AsyncTimerSequenceUnreliableActorTests repeatedly (100 times). There should be some errors. Whereas the similar AsyncTimerSequenceActorTests should be the same tests but on the working version of the sequence.
The text was updated successfully, but these errors were encountered: