Skip to content

Commit 613b2a8

Browse files
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 7a82b43. Signed-off-by: Luke Bakken <[email protected]>
1 parent 5f549ef commit 613b2a8

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/rabbit_connection_tracking_handler.erl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,14 @@ handle_event(#event{type = vhost_deleted, props = Details}, State) ->
8282
close_connections(rabbit_connection_tracking:list(VHost),
8383
rabbit_misc:format("vhost '~s' is deleted", [VHost])),
8484
{ok, State};
85+
%% Note: under normal circumstances this will be called immediately
86+
%% after the vhost_deleted above. Therefore we should be careful about
87+
%% what we log and be more defensive.
8588
handle_event(#event{type = vhost_down, props = Details}, State) ->
8689
VHost = pget(name, Details),
8790
Node = pget(node, Details),
88-
rabbit_log_connection:info("Closing all connections in vhost '~s' at node '~s'"
89-
" because the vhost database has stopped working",
91+
rabbit_log_connection:info("Closing all connections in vhost '~s' on node '~s'"
92+
" because the vhost is stopping",
9093
[VHost, Node]),
9194
close_connections(rabbit_connection_tracking:list_on_node(Node, VHost),
9295
rabbit_misc:format("vhost '~s' is down", [VHost])),
@@ -131,7 +134,17 @@ close_connections(Tracked, Message, Delay) ->
131134
ok.
132135

133136
close_connection(#tracked_connection{pid = Pid, type = network}, Message) ->
134-
rabbit_networking:close_connection(Pid, Message);
137+
try
138+
rabbit_networking:close_connection(Pid, Message)
139+
catch error:{not_a_connection, _} ->
140+
%% could has been closed concurrently, or the input
141+
%% is bogus. In any case, we should not terminate
142+
ok;
143+
_:Err ->
144+
%% ignore, don't terminate
145+
rabbit_log:warning("Could not close connection ~p: ~p", [Pid, Err]),
146+
ok
147+
end;
135148
close_connection(#tracked_connection{pid = Pid, type = direct}, Message) ->
136149
%% Do an RPC call to the node running the direct client.
137150
Node = node(Pid),

0 commit comments

Comments
 (0)