simple_one_for_one start_child() returns already_started
Asked Answered
B

1

12

I have a supervisor which should start simple_one_for_one workers. When I call start_child() for the first time, everything goes excellent. But, when I do it the second time, I get {error,{already_started,<0.71.0>}}. Why would simple_one_for_one supervisor return me a already_started? What am I missing?

Here is the code: supervisor, worker.

Bisulfate answered 23/7, 2011 at 6:19 Comment(4)
You're going to be awfully confused with your gen server handling messages by spawning a child to send a message to itself and then blocking while waiting to receive that message.Wisnicki
Why? I do the work in separate child to prevent gen_server from crashing. Is that a bad thing to do? Advice would be much appreciated :-)Bisulfate
Would it be a catastrophe if the gen_server crashed? It will be restarted by the supervisor. If you are worried about errors then wrap the call instead with a try ... catch ... end. While processes are cheap there is no gain in creating them unnecessarily and here there is no concurrency.Libido
Can you post the code here? If that link ever breaks, this question will be useless.Fateful
T
22

you are registering a (local) name for your gen_server. once you start one, you can not start another one with the same name.

if you use gen_server:start_link/3 instead, removing the first argument from your current gen_server:start_link/4 call, you should be able to start up more than one.

Thilde answered 23/7, 2011 at 6:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.