ocaml-multicore/domainslib

"Assert_failure lib/multi_channel.ml:70:2"

SGrondin opened this issue · 0 comments

First of all, thank you for the great library!

Fatal error: exception File "lib/multi_channel.ml", line 70, characters 2-8: Assertion failed
Raised at Stdlib__Domain.join in file "domain.ml", line 258, characters 16-24
Called from Eio__core__Fiber.fork.(fun) in file "lib_eio/core/fiber.ml", line 20, characters 10-14
Re-raised at Eio__core__Switch.maybe_raise_exs in file "lib_eio/core/switch.ml", line 116, characters 21-56
Called from Eio__core__Switch.run_internal in file "lib_eio/core/switch.ml", line 137, characters 4-21
Called from Eio__core__Cancel.with_cc in file "lib_eio/core/cancel.ml", line 116, characters 8-12
Re-raised at Eio__core__Cancel.with_cc in file "lib_eio/core/cancel.ml", line 118, characters 32-40
Called from Eio_posix__Sched.with_op in file "lib_eio_posix/sched.ml", line 300, characters 8-12
Re-raised at Eio_posix__Sched.with_op in file "lib_eio_posix/sched.ml", line 306, characters 4-12
Re-raised at Eio_posix__Sched.run.fork.(fun) in file "lib_eio_posix/sched.ml", line 321, characters 12-76
Called from Stdlib__Fun.protect in file "fun.ml", line 33, characters 8-15
Re-raised at Stdlib__Fun.protect in file "fun.ml", line 38, characters 6-52
Called from Eio_posix__Sched.run in file "lib_eio_posix/sched.ml", line 354, characters 4-217
Called from Eio_posix__Sched.with_sched in file "lib_eio_posix/sched.ml", line 244, characters 8-12
Re-raised at Eio_posix__Sched.with_sched in file "lib_eio_posix/sched.ml", line 249, characters 4-39
Called from Dune__exe__Strings in file "src/cli/strings.ml", line 26, characters 2-234

This exception occurs when code running in Eio.Domain_manager.run invokes Domainslib.Task.async.

The following code fails with an assertion error.

I'm using MacOS, OCaml 5.0.0, eio 0.10, eio_posix 0.10, domainslib 0.5.0. It also fails with the latest commit from Domainslib's main branch (14fe8fd6f0c46806efe46dfd1720a44a21edad2a).

open Eio.Std

(* Taken from Eio README.md *)
let pool = Domainslib.Task.setup_pool ~num_domains:2 ()

(* Taken from Eio README.md *)
let run_in_pool fn x =
  let result, set_result = Promise.create () in
  let (_ : unit Domainslib.Task.promise) =
    Domainslib.Task.async pool (fun () ->
      Promise.resolve set_result
      @@
      match fn x with
      | r -> Ok r
      | exception ex -> Error ex )
  in
  Promise.await_exn result

(* Minimal case *)
let () =
  Eio_main.run @@ fun env ->
  Switch.run @@ fun sw ->
  List.init 4 (fun _ -> ())
  |> Fiber.List.iter @@ fun () ->
     Fiber.fork ~sw @@ fun () -> Eio.Domain_manager.run env#domain_mgr @@ run_in_pool (fun () -> ())

The reason I'm even opening an issue is because I couldn't find anything in the docs of either Domainslib or Eio (or this guide) discouraging the above pattern.

It seems obvious enough of a pattern to me that my reaction was to think "I'm clearly doing something illegal". Is it a bug? Or just incomplete docs?