[erlang-questions] start_child() on simple_one_for_one supervisor -> {error, {already_started, ...}} ???
mighty
mighty.fine@REDACTED
Sun Dec 14 11:50:35 CET 2008
I have a basic simple_one_for_one supervisor that I cannot start
multiple children from -- the first call to start_child() works, the
second call to start_child() returns
{error,{already_started,<0.38.0>}}. My supervisor is
simple_one_for_one, so I'd expect to hit the ?is_simple() handling of
start_child in supervisor.erl, which should go through
supervisor:do_start_child_i() without any fuss, and definitely not
return {error, {already_started, ...}} out of
supervisor:handle_start_child().
TIA for helping me figure out what I'm messing up and keeping the rest
of the hair on my head!
############################################################################
Console output:
Erlang (BEAM) emulator version 5.6.5 [source] [smp:2]
[async-threads:0] [kernel-poll:false]
Eshell V5.6.5 (abort with ^G)
1> application:start(my).
=INFO REPORT==== 14-Dec-2008::02:29:03 ===
[my_app,start,normal,[]]
=INFO REPORT==== 14-Dec-2008::02:29:03 ===
[my_sup,start_link]
ok
2> my_node:start(99).
=INFO REPORT==== 14-Dec-2008::02:29:13 ===
[my_node,start_link,99,<0.36.0>]
{ok,<0.38.0>}
3> my_node:start(11).
=INFO REPORT==== 14-Dec-2008::02:29:20 ===
[my_node,start_link,11,<0.36.0>]
{error,{already_started,<0.38.0>}}
4>
############################################################################
my.app:
{application, my,
[{description, "My Stuff"}, {vsn, "0.1"}, {modules, [my_app,
my_sup, my_node]},
{registered, []}, {mod, {my_app, []}}, {applications, [kernel, stdlib]}]}.
############################################################################
my_app.erl:
-module(my_app).
-behaviour(application).
-export([start/2, stop/1]).
start(_Type, _StartArgs) ->
error_logger:info_report([[my_app, start, _Type, _StartArgs]]),
my_sup:start_link().
stop(_State) ->
error_logger:info_report([[my_app, stop, _State]]),
ok.
############################################################################
my_sup.erl:
-module(my_sup).
-behaviour(supervisor).
-export([start_link/0, init/1]).
start_link() ->
error_logger:info_report([[my_sup, start_link]]),
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
init([]) ->
Node = {my_node,
{my_node, start_link, []},
permanent,
brutal_kill,
worker,
[my_node]},
{ok, {{simple_one_for_one, 10, 1}, [Node]}}.
############################################################################
my_node.erl
-module(my_node).
-behaviour(gen_server).
-export([start/1, start_link/1]).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
-record(state, {}).
start(Instance) ->
supervisor:start_child(my_sup, [Instance]).
start_link(Instance) ->
error_logger:info_report([[my_node, start_link, Instance, self()]]),
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
init([]) ->
{ok, #state{}}.
handle_call(_Request, _From, State) ->
Reply = ok,
{reply, Reply, State}.
handle_cast(_Msg, State) ->
{noreply, State}.
handle_info(_Info, State) ->
{noreply, State}.
terminate(_Reason, _State) ->
ok.
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
More information about the erlang-questions
mailing list