From 65689dc102f8699e32366f0fcd5e53c0aa5c822b Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sat, 16 Nov 2024 10:12:59 +0000 Subject: [PATCH] Preserve backtraces in fork_daemon and fork_promise_exn 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. --- lib_eio/core/fiber.ml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib_eio/core/fiber.ml b/lib_eio/core/fiber.ml index 3113e8cc..dbf6cfd4 100644 --- a/lib_eio/core/fiber.ml +++ b/lib_eio/core/fiber.ml @@ -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 = @@ -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