[erlang-bugs] simple_one_by_one doesnt join args list properly

Angel J. Alvarez Miguel clist@REDACTED
Sun Jun 24 09:07:19 CEST 2012


Gist for this issue

 git://gist.github.com/2978625.git


/Angel

On Sábado, 23 de Junio de 2012 00:33:18 Angel J. Alvarez Miguel escribió:
> Hi
> 
> simple_one_for_one doesnt joint well args from childspec and start_child
> calls...
> 
> group_supervisor:init/1
> 
> init(Opts) ->                 & Opts is a large property list from cmd-line
> args parsed with getopt {ok, {
>          {simple_one_for_one, 1, 60},
>          [
>             {mucfsm,      {sim_group_fsm,      start_link, [Opts]}, 
> transient, 60, worker, [sim_group]} ]
>          }
>    }.
> 
> 
> 
> test:main/0
> 
> main() ->
>     io:format("Starting simple_one_by_one group supervisor...\n"),
>     SuppOpts = [{ŕecursive,true},{option1,40}],                            
>                % This root property list all sup children will inherit it
> {ok,Pid} = group_supervisor:start_link(SuppOpts),
>     wait(5),
>     io:format("Adding a child dynamically...\n",[]),
>     FSMOpts = [{fsm2,100}],                                            %
> This is another property list  we want new children to see it also
> {ok,_ChildPid} = supervisor:start_child(Pid,[FSMOpts]),
>     wait(20).
> 
> 
> children running sim_group_fsm should be started as :
> 
> sim_group_fsm:start_link/1 but sup builds args list the worng way
> thustrying to call undefined functions
> 
> start_link/n
> 
> with n > 1
> 
> 
> As docs state that simple_one_by_one sup will do apply(M,F,A) where A =
> ArgsFromChildSpec ++ ArgsFromStartChild call but as gen_fsm start_link is
> always arity ONE , supervisor must enclose A ina list to enrure always
> arity ONE.
> 
> I provide an example... and a patch
> 
> Im currently using a local patched version as i need using such a feature,
> howevre ive searched my local OTP installation and, most if not all
> {M,F,A} tuples in child specs era of the form A = [ ], also in most apps
> ive downloaded from GITHUB, so i think this feature of SOFO sups is
> probably not exercised enough, and nobody noticed this issue....
> 
> 
> Please take a look and show me the rigth way of doing this in case im
> wrong.
> 
> Regards, Angel
> 
> Patched supervidor example:
> 
> Erlang R15B01 (erts-5.9.1) [source] [64-bit] [smp:4:4] [async-threads:0]
> [hipe] [kernel-poll:false]
> 
> [QuickCheck] [PropEr] [Erl0MQ]
> Starting simple_one_by_one group supervisor...
> Eshell V5.9.1  (abort with ^G)
> [GROUP SUP] staring with argument: [{option1,40}]
> 1> [GROUP SUP] Ready to manage MuC with opts: [{option1,40}]'s
> Adding a child dynamically...
> start_link called with 1 argument: [[{option1,40}],[{fsm2,100}]]
> init fsm with args: [[{option1,40}],[{fsm2,100}]]
> Im alive!
> Im alive!
> Im alive!
> 
> 
> Original unpatched supervisor (stdllib 1.18.1)
> 
> erl -run test main
> [QuickCheck] [PropEr] [Erl0MQ]
> test.erl:11: Warning: variable 'ChildPid' is unused
> Erlang R15B01 (erts-5.9.1) [source] [64-bit] [smp:4:4] [async-threads:0]
> [hipe] [kernel-poll:false]
> 
> [QuickCheck] [PropEr] [Erl0MQ]
> Starting simple_one_by_one group supervisor...
> [GROUP SUP] staring with argument: [{option1,40}]
> Eshell V5.9.1  (abort with ^G)
> 1> [GROUP SUP] Ready to manage MuC with opts: [{option1,40}]'s
> Adding a child dynamically...
> {"init terminating in
> do_boot",{{badmatch,{error,{'EXIT',{undef,[{sim_group_fsm,start_link,[[{op
> tion1,40}],[{fsm2,100}]],[]},{supervisor,do_start_child_i,3,[{file,"supervi
> sor.erl"},{line,319}]},{supervisor,handle_call,3,[{file,"supervisor.erl"},{
> line,344}]},{gen_server,handle_msg,5,
> [{file,"gen_server.erl"},{line,588}]},{proc_lib,init_p_do_apply,3,[{file,"
> proc_lib.erl"},{line,227}]}]}}}},[{test,main,0,[{file,"test.erl"},{line,11}
> ]},{init,start_it,1,[]},{init,start_em,1,[]}]}}
> 
> Crash dump was written to: erl_crash.dump
> init terminating in do_boot ()



More information about the erlang-bugs mailing list