summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2011-08-08 17:05:55 +0100
committerSimon MacMullen <simon@rabbitmq.com>2011-08-08 17:05:55 +0100
commit7027bf9f23ea9ed96ba14ffb04668e72debbc393 (patch)
treef5354cfc9a9fb3c77e5fe031a69f0d84256e33fe /src
parent68e1af754a89c1a7ae93c36c0828198564649c1f (diff)
downloadrabbitmq-server-git-7027bf9f23ea9ed96ba14ffb04668e72debbc393.tar.gz
Don't delete from mnesia if child is running.
Diffstat (limited to 'src')
-rw-r--r--src/mirrored_supervisor.erl7
-rw-r--r--src/mirrored_supervisor_tests.erl1
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),