diff options
| -rw-r--r-- | src/mirrored_supervisor.erl | 7 | ||||
| -rw-r--r-- | src/mirrored_supervisor_tests.erl | 1 |
2 files changed, 6 insertions, 2 deletions
diff --git a/src/mirrored_supervisor.erl b/src/mirrored_supervisor.erl index bd32a6fd49..212ab23842 100644 --- a/src/mirrored_supervisor.erl +++ b/src/mirrored_supervisor.erl @@ -311,7 +311,6 @@ handle_call({start_child, ChildSpec}, _From, handle_call({delete_child, Id}, _From, State = #state{delegate = Delegate}) -> - {atomic, ok} = mnesia:transaction(fun() -> delete(Id) end), {reply, stop(Delegate, Id), State}; handle_call({msg, F, A}, _From, State = #state{delegate = Delegate}) -> @@ -422,7 +421,11 @@ start(Delegate, ChildSpec) -> apply(?SUPERVISOR, start_child, [Delegate, ChildSpec]). stop(Delegate, Id) -> - apply(?SUPERVISOR, delete_child, [Delegate, Id]). + case child(Delegate, Id) of + undefined -> {atomic, ok} = mnesia:transaction(fun() -> delete(Id) end), + apply(?SUPERVISOR, delete_child, [Delegate, Id]); + _ -> {error, running} + end. id({Id, _, _, _, _, _}) -> Id. diff --git a/src/mirrored_supervisor_tests.erl b/src/mirrored_supervisor_tests.erl index 9515eb7932..f3d7f1aca5 100644 --- a/src/mirrored_supervisor_tests.erl +++ b/src/mirrored_supervisor_tests.erl @@ -79,6 +79,7 @@ test_delete_restart() -> with_sups(fun([_, _]) -> S = childspec(worker), {ok, Pid1} = ?MS:start_child(a, S), + {error, running} = ?MS:delete_child(a, worker), ok = ?MS:terminate_child(a, worker), ok = ?MS:delete_child(a, worker), {ok, Pid2} = ?MS:start_child(b, S), |
