Skip to content

Commit

Permalink
Preserve backtraces in fork_daemon and fork_promise_exn
Browse files Browse the repository at this point in the history
If the fiber fails, record the backtrace when failing the switch. `fork`
itself already did this, but `fork_daemon` and `fork_promise_exn`
didn't.
  • Loading branch information
talex5 committed Nov 16, 2024
1 parent eb8fe3e commit 61f738d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib_eio/core/fiber.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ let fork_daemon ~sw f =
(* The daemon was cancelled because all non-daemon fibers are finished. *)
()
| exception ex ->
Switch.fail sw ex; (* The [with_daemon] ensures this will succeed *)
let bt = Printexc.get_raw_backtrace () in
Switch.fail ~bt sw ex; (* The [with_daemon] ensures this will succeed *)
) (* else the fiber should report the error to [sw], but [sw] is failed anyway *)

let fork_promise ~sw f =
Expand All @@ -65,7 +66,8 @@ let fork_promise_exn ~sw f =
match Switch.with_op sw f with
| x -> Promise.resolve r x
| exception ex ->
Switch.fail sw ex (* The [with_op] ensures this will succeed *)
let bt = Printexc.get_raw_backtrace () in
Switch.fail ~bt sw ex (* The [with_op] ensures this will succeed *)
);
p

Expand Down

0 comments on commit 61f738d

Please sign in to comment.