From 5f423e46d900d93a6a87ad2243124ec7fa894c93 Mon Sep 17 00:00:00 2001 From: Andras Boroska Date: Sat, 30 May 2015 23:57:20 +0100 Subject: Fix badarg exception when setting group_leader for a dead pid When setting up a shell some time elapses between listing the pids and setting the group_leader. If the process exited during that time then erlang:group_leader/2 will crash with badarg. --- src/rebar_prv_shell.erl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rebar_prv_shell.erl b/src/rebar_prv_shell.erl index c80badf..300f6fd 100644 --- a/src/rebar_prv_shell.erl +++ b/src/rebar_prv_shell.erl @@ -107,8 +107,10 @@ setup_shell() -> %% wait until user_drv and user have been registered (max 3 seconds) ok = wait_until_user_started(3000), %% set any process that had a reference to the old user's group leader to the - %% new user process - _ = [erlang:group_leader(whereis(user), Pid) || Pid <- NeedsUpdate], + %% new user process. Catch the race condition when the Pid exited after the + %% liveness check. + _ = [catch erlang:group_leader(whereis(user), Pid) || Pid <- NeedsUpdate, + is_process_alive(Pid)], %% enable error_logger's tty output ok = error_logger:swap_handler(tty), %% disable the simple error_logger (which may have been added multiple -- cgit v1.1