FSharpx.Async icon indicating copy to clipboard operation
FSharpx.Async copied to clipboard

Async.Parallel swallows exceptions

Open thednaz opened this issue 5 years ago • 0 comments

Description

When running multiple asyncs using FSharpx.Async.Parallel, an exception thrown in one doesn't cancel the running of others. This isn't the behavior when running using F#'s built-in Async.

Repro steps

Run this simplified snippet and observe that async a still keeps printing.

let rec a: Async<unit> = async {
    do! Async.Sleep 1000
    printfn "Running"
    return! a
}

let b = async {
    failwith "Failure"
}

Async.Parallel(a, b) |> Async.RunSynchronously

Expected behavior

Just like in the built-in F# Async.Parallel, an exception thrown in one Async should cancel the entire Async, without waiting for that Async to complete (I believe it'll bubble down the CancellationToken to the other running Asyncs).

Actual behavior

Async a in the example will keep running and printing. If Async a is made to complete, then once it completes the exception will be propagated up to the caller as expected.

Known workarounds

Use F# built-in Async.Parallel.

Related information

  • Operating system - Windows
  • Branch - Master

thednaz avatar Oct 13 '20 21:10 thednaz