summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Klishin <michael@clojurewerkz.org>2017-08-01 02:46:51 +0300
committerMichael Klishin <michael@clojurewerkz.org>2017-08-01 02:46:51 +0300
commit613b2a8846fd7b031823f325e01337766a9cbdd5 (patch)
treecaf6540ad6ebb4d92713aea0f0e3acaed0b521d1
parent5f549efa29403a3e4e351c363e53aa900de320dc (diff)
downloadrabbitmq-server-git-613b2a8846fd7b031823f325e01337766a9cbdd5.tar.gz
Make connection tracking handler more defensive
When a vhost is deleted, both vhost_deleted and vhost_down will be emitted, resulting in double deletion. rabbit_networking:close_connection/1 therefore can throw an exception about an unknown connection pid. The handler needs to account for that. While at it, change log messages to be less alarming and simply mention vhost shutdown as opposed to "a database failure". References 7a82b43bf12b737250957081d0b0d84b21b3bf72. Signed-off-by: Luke Bakken <lbakken@pivotal.io>
-rw-r--r--src/rabbit_connection_tracking_handler.erl19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/rabbit_connection_tracking_handler.erl b/src/rabbit_connection_tracking_handler.erl
index 3ae17677e0..ca13700da0 100644
--- a/src/rabbit_connection_tracking_handler.erl
+++ b/src/rabbit_connection_tracking_handler.erl
@@ -82,11 +82,14 @@ handle_event(#event{type = vhost_deleted, props = Details}, State) ->
close_connections(rabbit_connection_tracking:list(VHost),
rabbit_misc:format("vhost '~s' is deleted", [VHost])),
{ok, State};
+%% Note: under normal circumstances this will be called immediately
+%% after the vhost_deleted above. Therefore we should be careful about
+%% what we log and be more defensive.
handle_event(#event{type = vhost_down, props = Details}, State) ->
VHost = pget(name, Details),
Node = pget(node, Details),
- rabbit_log_connection:info("Closing all connections in vhost '~s' at node '~s'"
- " because the vhost database has stopped working",
+ rabbit_log_connection:info("Closing all connections in vhost '~s' on node '~s'"
+ " because the vhost is stopping",
[VHost, Node]),
close_connections(rabbit_connection_tracking:list_on_node(Node, VHost),
rabbit_misc:format("vhost '~s' is down", [VHost])),
@@ -131,7 +134,17 @@ close_connections(Tracked, Message, Delay) ->
ok.
close_connection(#tracked_connection{pid = Pid, type = network}, Message) ->
- rabbit_networking:close_connection(Pid, Message);
+ try
+ rabbit_networking:close_connection(Pid, Message)
+ catch error:{not_a_connection, _} ->
+ %% could has been closed concurrently, or the input
+ %% is bogus. In any case, we should not terminate
+ ok;
+ _:Err ->
+ %% ignore, don't terminate
+ rabbit_log:warning("Could not close connection ~p: ~p", [Pid, Err]),
+ ok
+ end;
close_connection(#tracked_connection{pid = Pid, type = direct}, Message) ->
%% Do an RPC call to the node running the direct client.
Node = node(Pid),