Skip to content

Commit efe513c

Browse files
committed
Don't assume perf is still alive after sending it SIGTERM
We caught this in practice with certain builds of `perf`. This code seems pretty fishy, and I'd like to look into it further later: it's not obvious to me why `waitpid` would raise if the PID no longer exists. I would have expected `perf` to still be an unreaped child at this point. But, we do have ~identical logic in ferrying ^C to `perf` in `src/trace.ml` too... Signed-off-by: Tudor Brindus <[email protected]>
1 parent bacf0a0 commit efe513c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/perf_tool_backend.ml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,13 @@ module Recording = struct
440440

441441
let finish_recording t =
442442
Signal_unix.send_i Signal.term (`Pid t.pid);
443-
(* This should usually be a signal exit, but we don't really care, if it didn't produce
444-
a good perf.data file the next step will fail. *)
445-
let%map (res : Core_unix.Exit_or_signal.t) = Async_unix.Unix.waitpid t.pid in
446-
perf_exit_to_or_error res
443+
(* This should usually be a signal exit, but we don't really care, if it didn't
444+
produce a good perf.data file the next step will fail.
445+
446+
[Monitor.try_with] because [waitpid] raises if perf exited before we get here. *)
447+
match%map.Deferred Monitor.try_with (fun () -> Async_unix.Unix.waitpid t.pid) with
448+
| Ok res -> perf_exit_to_or_error res
449+
| Error _exn -> Ok ()
447450
;;
448451
end
449452

0 commit comments

Comments
 (0)