Closed
Description
Hi,
AsyncChannel can crash in the following context:
- start an iteration in a Task
- cancel the task while the AsyncChannel is being awaited
- send a value in the channel
Here is a test that crashes:
func test_cancel_when_only_one_iterator_while_waiting() async throws {
let channel = AsyncChannel<Int>()
let task = Task {
for await _ in channel {}
}
try await Task.sleep(nanoseconds: 1_000_000_000) // ensures the loop is waiting for a next value
task.cancel() // sets the inner state of the channel to awaiting but with 0 nexts
await channel.send(1) // tries to remove the first element of the awaiting state (which is empty) -> crash
}
linked to #143