Repository navigation
Conversation
8e83c85 to
63a942a
Compare
|
AMP: PR Review —
|
b5bdab9 to
68a7821
Compare
68a7821 to
3e84e86
Compare
| ok = terminate_one_for_all(Affected1), | ||
| {ok, NewAffected} = get_restart_children(Affected1), | ||
| {noreply, State#state{children = lists:reverse(NewAffected) ++ Rest}, | ||
| {timeout, 0, {restart_many_children, NewAffected}}}. |
There was a problem hiding this comment.
This conflicts with release-0.7 (fd66292 and acefe17).
On rebase, please switch this to the new mechanism, the same way one_for_all now does it: self() ! '$atomvm_restart_many_children' with restart_queue = restart_ids(NewAffected).
Otherwise this path brings back both problems: a call or 'EXIT' arriving mid-restart leaves the remaining children stuck in {restarting, _}, and the message carries #child{} records, so any sender can make the supervisor call an arbitrary MFA.
| {error, _} -> | ||
| NewChild = Child#child{pid = {restarting, Child#child.pid}}, | ||
| Children = lists:keyreplace(Id, #child.id, State#state.children, NewChild), | ||
| {noreply, State#state{children = Children}, {timeout, 0, {try_again_restart, Id}}} |
There was a problem hiding this comment.
restart_one and restart_simple_one helpers return {timeout, 0, {try_again_restart, Id}}. That was the bug fixed in acefe17: the next incoming message cancels the retry, so the child stays {restarting, _} forever. Please port them to self() ! '$atomvm_try_again_restart' and append Id to retry_queue, the way the current one_for_one clause on release-0.7 does. The same applies at line 633.
| case add_restart(State) of | ||
| {ok, State1} -> | ||
| case try_start(Child) of | ||
| {ok, undefined, _Result} when |
There was a problem hiding this comment.
On release-0.7, the '$atomvm_try_again_restart' handler only matches #child{pid = {restarting, _}} and re-queues with retry_queue = Ids ++ [Id]. Please carry the {ok, undefined, _} when simple_one_for_one drop branch into that handler, so the case covered by test_simple_one_for_one_ignore_on_restart still works through the retry path.
| - Added a `hex_package` build target that builds the `atomvm` Hex package, published on | ||
| hex.pm by CI when a release is tagged, so that build tools can check a project against | ||
| the AtomVM release it targets | ||
| - Added support for `rest_for_one` and `simple_one_for_one` supervisor restart strategies |
There was a problem hiding this comment.
Let's move this to 0.7.0-beta.1.
| type => worker, | ||
| modules => [?MODULE] | ||
| }, | ||
| {ok, {#{strategy => simple_one_for_one, intensity => 10, period => 60}, [Template]}}; |
There was a problem hiding this comment.
Every failed retry calls add_restart, and the retry loop runs back-to-back. With intensity 10, the supervisor can shut down before terminate_child/2 gets in, especially on SMP builds. Today the test likely passes partly because the call cancels the {timeout, 0} retry, and that changes after the rebase. Please raise the intensity (e.g. 1000), or make the worker fail a bounded number of times and then block.
| stop -> ok | ||
| end. | ||
|
|
||
| test_rest_for_one() -> |
There was a problem hiding this comment.
release-0.7 has test_restart_survives_messages_one_for_all and test_retry_survives_messages_one_for_one. A rest_for_one version, where a which_children call or an unrelated 'EXIT' arrives during a partial restart, would guard the rebased path above.
3e84e86 to
35eafd7
Compare
| pid = {restarting, Pid} | ||
| }) | ||
| end, | ||
| ok = terminate_one_for_all(Affected1), |
There was a problem hiding this comment.
terminate_one_for_all/1 waits in loop_wait_termination/1, which consumes every {'EXIT', _, _} in the mailbox, not only those of the children being stopped. With one_for_all that is harmless because every child is being stopped anyway. With rest_for_one the children started before the crashed one keep running: if one of them exits during this wait (up to the siblings' shutdown timeout), its 'EXIT' is lost, it is never restarted, and the supervisor keeps its dead pid in children (which_children keeps reporting it). OTP restarts it once the rest_for_one restart is done.
Reproduced with children a, b, c where c has shutdown => 2000, traps exits and takes 500 ms to stop: crash b, kill a while c is stopping. On this branch a stays dead; on OTP a is restarted.
35eafd7 to
a7ea86b
Compare
bettio
left a comment
There was a problem hiding this comment.
There are still few issues.
| loop_wait_termination(RemainingChildren0) -> | ||
| loop_wait_termination([Pid | Rest] = Pids) -> | ||
| receive | ||
| {'EXIT', Pid, _Reason} -> |
There was a problem hiding this comment.
This loop no longer swallows unrelated 'EXIT's, but it still consumes every '$atomvm_ensure_killed' and drops the ones whose pid is not in Pids. With one_for_all every live child is in Pids; with rest_for_one the children started before the crashed one are not. If terminate_child/2 is pending on one of them and its shutdown timeout expires during this wait, the kill is lost: a child that ignores shutdown is never killed, and the caller (infinity timeout) never gets its reply.
Reproduced with a (shutdown => 300, traps exits and ignores them), b, c (takes 1 s to stop): call terminate_child(Sup, a), kill b 50 ms later. On this branch the call never returns and a stays alive; on OTP, or with one_for_one here, it returns ok after 300 ms.
Please keep kill requests for pids outside Pids for handle_info/2, for example by collecting them and sending them back to self() when the wait ends.
| {ok, Pid, Result} -> | ||
| {reply, Result, State#state{children = [NewChild#child{pid = Pid} | Children]}}; | ||
| {error, _Reason} = ErrorT -> | ||
| {reply, ErrorT, State} |
There was a problem hiding this comment.
For simple_one_for_one, OTP replies with the start function's error unchanged: {error, Reason}. This replies with try_start/1's {error, {Reason, #child{}}}, so the common {error, {already_started, Pid}} match fails (the caller gets {error, {{already_started, Pid}, {child, ...}}}) and the internal record leaks out. Please unwrap it: {error, {Reason, _Child}} -> {reply, {error, Reason}, State}.
| ), | ||
| {reply, ok, State#state{children = NewChildren}}; | ||
| false -> | ||
| {reply, {error, not_found}, State} |
There was a problem hiding this comment.
OTP returns {error, not_found} only for a pid that is alive and not a child; for a pid that is no longer alive it returns ok. Here, terminating a child that already exited on its own, was already terminated, or was replaced by a restart returns {error, not_found}, so ok = supervisor:terminate_child(Sup, Pid) fails whenever the child exits first. Please reply ok when is_process_alive(Pid) is false.
a7ea86b to
3662320
Compare
For simple_one_for_one, drop a dynamic child whose restart returns ignore and let terminate_child/2 cancel a pending restart by the original pid, as OTP does. Signed-off-by: Paul Guyot <pguyot@kallisys.net>
3662320 to
cc65810
Compare
These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).
SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later