Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Supervising multiple gen_servers with same module / different arguments

I have a OTP application comprising a single supervisor supervising a small number of gen_servers. A typical child specification is as follows:

{my_server,
  {my_server, start_link, [123]},
  permanent, 
  5000, 
  worker,
  [my_server]}

No problems so far.

I now want to an add extra gen_server to the supervisor structure, using the same module Module/Fn as above, but different arguments, eg

{my_server_2,
  {my_server, start_link, [123]},
  permanent, 
  5000, 
  worker,
  [my_server_2]}

I thought this would work, but no:

=SUPERVISOR REPORT==== 15-Apr-2010::16:50:13 ===
     Supervisor: {local,my_sup}
     Context:    start_error
     Reason:     {already_started,<0.179.0>}
     Offender:   [{pid,undefined},
                  {name,my_server_2},
                  {mfa,{my_server,start_link,[]}},
                  {restart_type,permanent},
                  {shutdown,5000},
                  {child_type,worker}]

Do the module arguments in the second element of each child specification need to be different ?

Thanks,

Justin

like image 234
Justin Avatar asked Feb 28 '23 04:02

Justin


1 Answers

My guess is that my_server registers its name using using gen_server:start_link/4, so that when the second one tries to start it can't because the name is already taken. The gen_servers will either have to start without a name (gen_server:start_link/3) or with different names.

It seems strange to vary the last element of the child spec, which identifies the list of modules used by the worker. Is this really what you intend?

like image 57
cthulahoops Avatar answered May 08 '23 12:05

cthulahoops