Skip to content

Commit 2410edc

Browse files
committed
Preserve backtraces in fork_daemon and fork_promise
If the fiber fails, record the backtrace when failing the switch. `fork` itself already did this, but `fork_daemon` and `fork_promise` didn't.
1 parent eb8fe3e commit 2410edc

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib_eio/core/fiber.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ let fork_daemon ~sw f =
3939
(* The daemon was cancelled because all non-daemon fibers are finished. *)
4040
()
4141
| exception ex ->
42-
Switch.fail sw ex; (* The [with_daemon] ensures this will succeed *)
42+
let bt = Printexc.get_raw_backtrace () in
43+
Switch.fail ~bt sw ex; (* The [with_daemon] ensures this will succeed *)
4344
) (* else the fiber should report the error to [sw], but [sw] is failed anyway *)
4445

4546
let fork_promise ~sw f =
@@ -65,7 +66,8 @@ let fork_promise_exn ~sw f =
6566
match Switch.with_op sw f with
6667
| x -> Promise.resolve r x
6768
| exception ex ->
68-
Switch.fail sw ex (* The [with_op] ensures this will succeed *)
69+
let bt = Printexc.get_raw_backtrace () in
70+
Switch.fail ~bt sw ex (* The [with_op] ensures this will succeed *)
6971
);
7072
p
7173

0 commit comments

Comments
 (0)