diff options
author | Andras Boroska <andras.boroska@gmail.com> | 2015-05-30 23:57:20 +0100 |
---|---|---|
committer | Andras Boroska <andras.boroska@gmail.com> | 2015-05-30 23:57:20 +0100 |
commit | 5f423e46d900d93a6a87ad2243124ec7fa894c93 (patch) | |
tree | 8d1f95d77c35ec2e80ee816f150e9cdf594e7ace | |
parent | 4ac482e01826a01572ebbc735baed9ad81012c4a (diff) |
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.
-rw-r--r-- | src/rebar_prv_shell.erl | 6 |
1 files 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 |