Skip to content

Commit

Permalink
Give a good error message when waitpid raises
Browse files Browse the repository at this point in the history
This behavior is best demonstrated by the report in #210, where perf
crashed and that made magic-trace crash. Let's nudge people that perf
may have crashed, instead.
  • Loading branch information
cgaebel committed May 27, 2022
1 parent 7e457f9 commit 5f487e5
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/trace.ml
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,18 @@ module Make_commands (Backend : Backend_intf.S) = struct
| Core_unix.Unix_error (_, (_ : string), (_ : string)) ->
(* We raced, but it's OK because the child still exited. *)
());
let%bind.Deferred (_ : Core_unix.Exit_or_signal.t) = Async_unix.Unix.waitpid pid in
(* [Monitor.try_with] because [waitpid] raises if perf died before we got here. *)
let%bind.Deferred (waitpid_result : (Core_unix.Exit_or_signal.t, exn) result) =
Monitor.try_with (fun () -> Async_unix.Unix.waitpid pid)
in
(match waitpid_result with
| Ok _ -> ()
| Error error ->
Core.eprintf
!"Warning: [perf] exited suspiciously quickly; it may have crashed.\n\
Error: %{Exn}\n\
%!"
error);
(* This is still a little racey, but it's the best we can do without pidfds. *)
Ivar.fill exited_ivar ();
let%bind () = detach attachment in
Expand Down

0 comments on commit 5f487e5

Please sign in to comment.