Skip to content

Commit a1c79a7

Browse files
author
Simon MacMullen
committed
We need to distinguish between the already_started we make get back from the real supervisor (which we need to treat as a real error at init) and the one we cons up ourselves (which we can ignore at init since in general all the mirrored sups in a group will have the same childspecs). But we treat them both as errors for start_child though.
1 parent eb00309 commit a1c79a7

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/mirrored_supervisor.erl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,11 @@ handle_call({init, Overall}, _From,
357357
handle_call({start_child, ChildSpec}, _From,
358358
State = #state{delegate = Delegate,
359359
group = Group}) ->
360-
{reply, maybe_start(Group, Delegate, ChildSpec), State};
360+
{reply, case maybe_start(Group, Delegate, ChildSpec) of
361+
already_in_mnesia -> {error, already_present};
362+
{already_in_mnesia, Pid} -> {error, {already_started, Pid}};
363+
Else -> Else
364+
end, State};
361365

362366
handle_call({delete_child, Id}, _From, State = #state{delegate = Delegate,
363367
group = Group}) ->
@@ -436,8 +440,8 @@ maybe_start(Group, Delegate, ChildSpec) ->
436440
check_start(Group, Delegate, ChildSpec)
437441
end) of
438442
{atomic, start} -> start(Delegate, ChildSpec);
439-
{atomic, undefined} -> {error, already_present};
440-
{atomic, Pid} -> {error, {already_started, Pid}};
443+
{atomic, undefined} -> already_in_mnesia;
444+
{atomic, Pid} -> {already_in_mnesia, Pid};
441445
%% If we are torn down while in the transaction...
442446
{aborted, E} -> {error, E}
443447
end.

0 commit comments

Comments
 (0)