scottstots
scottstots

Reputation: 193

Erlang: supervisor:terminate_child return error even in latest version

I'm trying to use a supervisor with simple_one_for_one RestartStrategy, and I think I have the latest version of Erlang, but still when I try to execute supervisor:terminate_child it ends up with {error,simple_one_for_one}. According to this answer, it should work if my Erlang is version is greater than R14B03 but I can't seem to find the version starting with 'R' anywhere. When I try erlang:system_info(otp_release) in the Erlang shell, it return with "24", which I think is the latest version released in May 2021, but I could see no other reason for this issue. Here is how my supervisor looks:

-module(a_sup).
-behaviour(supervisor).

%% API
-export([start_link/0, init/1]).

start_link() ->
  {ok, supervisor:start_link({local,?MODULE}, ?MODULE, [])}.

init(_Args) ->
  RestartStrategy = {simple_one_for_one, 5, 3600},
  ChildSpec = {
    a_gen_server,
    {a_gen_server, start_link, []},
    permanent,
    brutal_kill,
    worker,
    [a_gen_server]
  },
  {ok, {RestartStrategy,[ChildSpec]}}.

Upvotes: 1

Views: 92

Answers (1)

Steve Vinoski
Steve Vinoski

Reputation: 20004

You don't show your code for terminating a child, but are you indicating the child to terminate using an identifier instead of a pid? The terminate_child/2 documentation says:

If the supervisor is simple_one_for_one, Id must be the pid() of the child process. If the specified process is alive, but is not a child of the specified supervisor, the function returns {error,not_found}. If the child specification identifier is specified instead of a pid(), the function returns {error,simple_one_for_one}.

Regarding the version issue: 24.2 is the current Erlang/OTP version at the time of this writing. Version numbers used to start with 'R' but that ended at Erlang/OTP 17.0.

Upvotes: 4

Related Questions