Skip to content

AsyncChannel crash when cancelled with only one awaiting #142

Closed
@twittemb

Description

@twittemb

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    v1.0Work leading up first API stable version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions