Skip to content

Deadlock in Task.select when using clock's sleep  #139

@mbrandonw

Description

@mbrandonw

I'm using Swift dev snapshot 2022-03-02 with Xcode 13.3.

By making a small tweak to one of the Task.select tests I am able to produce a deadlock:

 let firstValue = await Task.select(Task {
+  try! await Task.sleep(until: .now + .seconds(1), clock: .continuous)
   return 1
 }, Task {
   try! await Task.sleep(until: .now + .seconds(2), clock: .continuous)
   return 2
 }).value

It's worth noting that it does not deadlock if you use Task.sleep without a clock:

let firstValue = await Task.select(Task {
  try! await Task.sleep(nanoseconds: NSEC_PER_SEC)
  return 1
}, Task {
  try! await Task.sleep(nanoseconds: 2*NSEC_PER_SEC)
  return 2
}).value

Is there something about clocks and sleeping that is causing this? I see the same behavior with suspending clocks too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ResolvedQuestion answered or otherwise resolved

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions