Przeglądaj źródła

Fix bugs/race conditions

Following suggestions from @psyeugenic, this code terminates and waits
for the termination of the port handling IO before booting our own,
which should get rid of annoying warnings.

We also allow for the failure to shutdown the user worker under
kernel_sup, since it is likely not there anymore in many scenarios,
preventing crashes.
pull/1124/head
Fred Hebert 9 lat temu
rodzic
commit
8e6a1ad62e
1 zmienionych plików z 16 dodań i 2 usunięć
  1. +16
    -2
      src/rebar_prv_shell.erl

+ 16
- 2
src/rebar_prv_shell.erl Wyświetl plik

@ -133,11 +133,25 @@ kill_old_user() ->
%% fully die %% fully die
[P] = [P || P <- element(2,process_info(whereis(user), links)), is_port(P)], [P] = [P || P <- element(2,process_info(whereis(user), links)), is_port(P)],
user ! {'EXIT', P, normal}, % pretend the port died, then the port can die! user ! {'EXIT', P, normal}, % pretend the port died, then the port can die!
exit(P, kill),
wait_for_port_death(1000, P),
OldUser. OldUser.
wait_for_port_death(N, _) when N < 0 ->
%% This risks displaying a warning!
whatever;
wait_for_port_death(N, P) ->
case erlang:port_info(P) of
undefined ->
ok;
_ ->
timer:sleep(10),
wait_for_port_death(N-10, P)
end.
setup_new_shell() -> setup_new_shell() ->
%% terminate the current user supervision structure
ok = supervisor:terminate_child(kernel_sup, user),
%% terminate the current user supervision structure, if any
_ = supervisor:terminate_child(kernel_sup, user),
%% start a new shell (this also starts a new user under the correct group) %% start a new shell (this also starts a new user under the correct group)
_ = user_drv:start(), _ = user_drv:start(),
%% wait until user_drv and user have been registered (max 3 seconds) %% wait until user_drv and user have been registered (max 3 seconds)

Ładowanie…
Anuluj
Zapisz