I have a supervisor. I get child_specs from the child which is a gen_server. I first wrote this for a single supervisor - child relation. Later I wanted that supervisor to start many childs. But I have some ets tables as state in the child gen_server. So when the supervisor is trying to create the second child it is throwing an exception like:
exception exit: {shutdown,
{failed_to_start_child,bench_client2,
{badarg,
[{ets,new,[config,[set,named_table]],[]},
{bench_client,init,1,
[{file,"bench_client.erl"},{line,59}]},
{gen_server,init_it,6,
[{file,"gen_server.erl"},{line,306}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,237}]}]}}}
I am guessing that since ets is shared, when the supervisor goes to the init function of the second child it already sees a ets table and so the exception but not sure how to get around. only a guess, though.
This is how I am getting the child specs from the child gen_server
child_specs() ->
[begin
Name = list_to_atom(?MODULE_STRING ++ integer_to_list(Index)),
{Name, {?MODULE, start_link, [Name]},
transient, 2000, worker, [bench_client]}
end || Index <- lists:seq(1, 20)].
init() function of the gen_server is
init([]) ->
Config = ets:new(config, [set, named_table]),
Destinations = ets:new(destinations, [set, named_table]),
I am a complete beginner in erlang and thus having a hard time.
Thank you !