Skip to content

Commit

Permalink
stdlib: Fix proc_lib:stop when exit reason is expected reason
Browse files Browse the repository at this point in the history
  • Loading branch information
garazdawi committed Sep 2, 2024
1 parent 6a5bf81 commit be42628
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/stdlib/src/proc_lib.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1573,20 +1573,25 @@ about system messages, see `m:sys` and section
stop(Process, Reason, Timeout) ->
Mref = erlang:monitor(process, Process),
T0 = erlang:monotonic_time(millisecond),
StopTimeout = fun(infinity) -> infinity;
(T1) -> T1 - (((erlang:monotonic_time(microsecond) + 999) div 1000) - T0)
end,
RemainingTimeout = try
sys:terminate(Process, Reason, Timeout)
of
ok when Timeout =:= infinity ->
infinity;
ok ->
Timeout - (((erlang:monotonic_time(microsecond) + 999) div 1000) - T0)
ok -> StopTimeout(Timeout)
catch
exit:{noproc, {sys, terminate, _}} ->
demonitor(Mref, [flush]),
exit(noproc);
exit:{timeout, {sys, terminate, _}} ->
demonitor(Mref, [flush]),
exit(timeout);
exit:{Reason, {sys, terminate, _}} ->
demonitor(Mref, [flush]),
StopTimeout(Timeout);
exit:Reason1 ->
demonitor(Mref, [flush]),
exit(Reason1)
Expand Down

0 comments on commit be42628

Please sign in to comment.