summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Klishin <michael@clojurewerkz.org>2019-03-06 23:14:42 +0300
committerMichael Klishin <michael@clojurewerkz.org>2019-03-06 23:14:42 +0300
commit1e511044a046febffa0fb2ef2db0db2db6d311a1 (patch)
treeecdbd6649196bcc56935b4751c1817aeaa62270a
parent3bdc83d6be17c648e7a13d3e6d912859e7c0c150 (diff)
downloadrabbitmq-server-git-1e511044a046febffa0fb2ef2db0db2db6d311a1.tar.gz
Make link sup sup startup idempotent
By handling `{error, already_started}` which can be seen in the wild due to distributed race conditions. Per discussion with @lukebakken.
-rw-r--r--deps/rabbitmq_federation/src/rabbit_federation_exchange_link_sup_sup.erl17
-rw-r--r--deps/rabbitmq_federation/src/rabbit_federation_queue_link_sup_sup.erl17
2 files changed, 30 insertions, 4 deletions
diff --git a/deps/rabbitmq_federation/src/rabbit_federation_exchange_link_sup_sup.erl b/deps/rabbitmq_federation/src/rabbit_federation_exchange_link_sup_sup.erl
index efcb8eaff1..6c415b8432 100644
--- a/deps/rabbitmq_federation/src/rabbit_federation_exchange_link_sup_sup.erl
+++ b/deps/rabbitmq_federation/src/rabbit_federation_exchange_link_sup_sup.erl
@@ -42,7 +42,12 @@ start_child(X) ->
{id(X), {rabbit_federation_link_sup, start_link, [X]},
transient, ?SUPERVISOR_WAIT, supervisor,
[rabbit_federation_link_sup]}) of
- {ok, _Pid} -> ok;
+ {ok, _Pid} -> ok;
+ {error, already_started} ->
+ #exchange{name = ExchangeName} = X,
+ rabbit_log_federation:debug("Federation link for exchange ~p was already started",
+ [rabbit_misc:rs(ExchangeName)]),
+ ok;
%% A link returned {stop, gone}, the link_sup shut down, that's OK.
{error, {shutdown, _}} -> ok
end.
@@ -53,7 +58,15 @@ adjust(Reason) ->
ok.
stop_child(X) ->
- ok = mirrored_supervisor:terminate_child(?SUPERVISOR, id(X)),
+ case mirrored_supervisor:terminate_child(?SUPERVISOR, id(X)) of
+ ok -> ok;
+ {error, Err} ->
+ #exchange{name = ExchangeName} = X,
+ rabbit_log_federation:warning(
+ "Attempt to stop a federation link for exchange ~p failed: ~p",
+ [rabbit_misc:rs(ExchangeName), Err]),
+ ok
+ end,
ok = mirrored_supervisor:delete_child(?SUPERVISOR, id(X)).
%%----------------------------------------------------------------------------
diff --git a/deps/rabbitmq_federation/src/rabbit_federation_queue_link_sup_sup.erl b/deps/rabbitmq_federation/src/rabbit_federation_queue_link_sup_sup.erl
index faa94abc3b..9cb0780b60 100644
--- a/deps/rabbitmq_federation/src/rabbit_federation_queue_link_sup_sup.erl
+++ b/deps/rabbitmq_federation/src/rabbit_federation_queue_link_sup_sup.erl
@@ -41,7 +41,12 @@ start_child(Q) ->
{id(Q), {rabbit_federation_link_sup, start_link, [Q]},
transient, ?SUPERVISOR_WAIT, supervisor,
[rabbit_federation_link_sup]}) of
- {ok, _Pid} -> ok;
+ {ok, _Pid} -> ok;
+ {error, already_started} ->
+ QueueName = amqqueue:get_name(Q),
+ rabbit_log_federation:warning("Federation link for queue ~p was already started",
+ [rabbit_misc:rs(QueueName)]),
+ ok;
%% A link returned {stop, gone}, the link_sup shut down, that's OK.
{error, {shutdown, _}} -> ok
end.
@@ -52,7 +57,15 @@ adjust(Reason) ->
ok.
stop_child(Q) ->
- ok = supervisor2:terminate_child(?SUPERVISOR, id(Q)),
+ case supervisor2:terminate_child(?SUPERVISOR, id(Q)) of
+ ok -> ok;
+ {error, Err} ->
+ QueueName = amqqueue:get_name(Q),
+ rabbit_log_federation:warning(
+ "Attempt to stop a federation link for queue ~p failed: ~p",
+ [rabbit_misc:rs(QueueName), Err]),
+ ok
+ end,
ok = supervisor2:delete_child(?SUPERVISOR, id(Q)).
%%----------------------------------------------------------------------------