From dd2c505890ba89938a4c9c8810c702d9158a2e1b Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Thu, 19 Dec 2019 07:37:03 -0800 Subject: [PATCH] [processpool] handle BoJo case Summary: Infer would crash when started in a context where it already had children it didn't know about. Reviewed By: martintrojer Differential Revision: D19177589 fbshipit-source-id: 0c8831597 --- infer/src/base/ProcessPool.ml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/infer/src/base/ProcessPool.ml b/infer/src/base/ProcessPool.ml index 6262198d2..336c8cd34 100644 --- a/infer/src/base/ProcessPool.ml +++ b/infer/src/base/ProcessPool.ml @@ -189,11 +189,15 @@ let killall pool ~slot status = let has_dead_child pool = + let open Option.Monad_infix in Unix.wait_nohang `Any - |> Option.map ~f:(fun (dead_pid, status) -> - ( Array.find_mapi_exn pool.slots ~f:(fun slot {pid} -> - if Pid.equal pid dead_pid then Some slot else None ) - , status ) ) + >>= fun (dead_pid, status) -> + (* Some joker can [exec] an infer binary from a process that already has children. When some of + these pre-existing children die they'll get detected here but won't appear in our list of + workers. Just return [None] in that case. *) + Array.find_mapi pool.slots ~f:(fun slot {pid} -> + if Pid.equal pid dead_pid then Some slot else None ) + >>| fun slot -> (slot, status) let child_is_idle = function Idle -> true | _ -> false