-
Notifications
You must be signed in to change notification settings - Fork 132
Fix several supervisor issues and bugs #1958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
e0f3afd to
7b2435d
Compare
pguyot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this work!
I looked at OTP's implementation and we're doing things differently, which may or may not be a good thing :)
OTP's terminate_child/2 is synchronous and I like the asynchronous implementation we currently have. Yet, it introduces some complexity.
I wonder if we should move further and make this entirely state based, i.e. avoid send_after/3 entirely and rely on timeout feature of gen_server instead for the general case, or just plain receive of exit messages for the terminate case. It may make this more easy to test or more pure. Also be careful of processing of messages with send_after because we don't know if the child is still there.
bc92215 to
bcce436
Compare
Fixes a typo in the init funtion error return where the atom `mod` was returned rather than the modules name (`Mod`). Fixes a typo in child record `type`, adds missing parenthesis on the `child_type/0` type. Signed-off-by: Winford <[email protected]>
Renames restart_child/3 to handle_child_exit/3 for clarity. This is an intenal callback handler, and not related to the exported restart_child/2. Signed-off-by: Winford <[email protected]>
Moves the internal private funtions `handle_child_exit/3` and `should_restart/2` to the same section as the rest of the internal private funtions. Signed-off-by: Winford <[email protected]>
Fixes some tests to catch the messages from child ping_pong_servers so they will not be received by later tests. Changes the supervisor started in test_count_children to use a generic supervisor without a child, rather than using the modules start_link which always starts a child ping_pong_server that sends messages back to the test environment. Fixes the test_ping_ping final `recieve` to match on a new `Pid4` (which would indicate a restart) rather than `Pid3` that the monitor just caught the 'DOWN' message for. Signed-off-by: Winford <[email protected]>
f0b6954 to
0017e5a
Compare
Adds support for handling restarts for the `one_for_all` strategy that was documented, but lacked implementation. Makes necessary changes to ensure children are always restarted in the same order they were originally started, and shutdown in reverse order with last child first, conforming to OTP behavior. Closes atomvm#1855 Signed-off-by: Winford <[email protected]>
0017e5a to
3c8849a
Compare
libs/estdlib/src/supervisor.erl
Outdated
| -type sup_ref() :: | ||
| (Name :: atom()) | ||
| | {Name :: atom(), Node :: node()} | ||
| | {global, Name :: term()} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we don't support these supervisor references (global, via) yet. We shouldn't include them in the types, so dialyzer would catch uses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
libs/estdlib/src/supervisor.erl
Outdated
| State = init_state(StartSpec, #state{restart_strategy = Strategy}), | ||
| {ok, {#{} = SupSpec, StartSpec}} -> | ||
| Strategy = maps:get(strategy, SupSpec, one_for_one), | ||
| Intensity = maps:get(intensity, SupSpec, 3), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have 1 as the default above and 3 here.
Should we have a macro for the default to avoid discrepacies?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. I added macros for the default intensity and period values.
3c8849a to
11474b5
Compare
Adds support for honoring intensity and period supervisor options, allowing the prevention of endless crash and restarts by misbehaving children. Adds a test to ensure the settings work as expected on AtomVM and match OTP. Closes atomvm#1915 Signed-off-by: Winford <[email protected]>
Fixes a function clause exception that would crash the supervisor if a child fails to restart by matching the same behavior as OTP, and continue to try restarting the child until success, or maximum `intensity` is reached within the allowed `period`. Closed atomvm#1957 Signed-off-by: Winford <[email protected]>
- Updates some types to match OTP, and adds some others, including exports types for `startchild_ret/0` and `startlink_ret/0`. - Adds a module doc section listing differences with OTP supervisor. - Adds specs to all public functions, and marks callbacks as hidden functions so they are not included in published user API docs. - Adds todos where child and supervisor event reports should be logged Signed-off-by: Winford <[email protected]>
11474b5 to
51cdbc9
Compare
These changes fix several open supervisor issues, as well as a few small bugs discovered in the supervisor and test_supervisor.erl.
one_for_allrestart strategy that is documented in the module.intensityandperiodoptions.test_supervisor:/test/0.Closes #1855
Closes #1915
Closed #1957
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