summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@lshift.net>2010-02-05 15:24:53 +0000
committerMatthias Radestock <matthias@lshift.net>2010-02-05 15:24:53 +0000
commit1b8334a74501d94ec527a23a239ac3dbe09decd0 (patch)
tree7c7bb905462874e734ed5b94b627b7298a76dfe4
parent1511c73a4ae414dd2ea87aa79e76bee495dd2db8 (diff)
downloadrabbitmq-server-1b8334a74501d94ec527a23a239ac3dbe09decd0.tar.gz
handle attempt to close connection with a non-connection pidbug22309
which was previously hanging at best and causing things to explode at worst
-rw-r--r--src/rabbit_control.erl2
-rw-r--r--src/rabbit_networking.erl11
2 files changed, 11 insertions, 2 deletions
diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl
index 2ea64753..8e38ee42 100644
--- a/src/rabbit_control.erl
+++ b/src/rabbit_control.erl
@@ -241,7 +241,7 @@ action(rotate_logs, Node, Args = [Suffix], Inform) ->
action(close_connection, Node, [PidStr, Explanation], Inform) ->
Inform("Closing connection ~s", [PidStr]),
- rpc_call(Node, rabbit_reader, shutdown,
+ rpc_call(Node, rabbit_networking, close_connection,
[rabbit_misc:string_to_pid(PidStr), Explanation]);
action(add_user, Node, Args = [Username, _Password], Inform) ->
diff --git a/src/rabbit_networking.erl b/src/rabbit_networking.erl
index 06e2b40e..717eccc4 100644
--- a/src/rabbit_networking.erl
+++ b/src/rabbit_networking.erl
@@ -35,7 +35,8 @@
stop_tcp_listener/2, on_node_down/1, active_listeners/0,
node_listeners/1, connections/0, connection_info_keys/0,
connection_info/1, connection_info/2,
- connection_info_all/0, connection_info_all/1]).
+ connection_info_all/0, connection_info_all/1,
+ close_connection/2]).
%%used by TCP-based transports, e.g. STOMP adapter
-export([check_tcp_listener_address/3]).
@@ -76,6 +77,7 @@
-spec(connection_info/2 :: (connection(), [info_key()]) -> [info()]).
-spec(connection_info_all/0 :: () -> [[info()]]).
-spec(connection_info_all/1 :: ([info_key()]) -> [[info()]]).
+-spec(close_connection/2 :: (pid(), string()) -> 'ok').
-spec(on_node_down/1 :: (erlang_node()) -> 'ok').
-spec(check_tcp_listener_address/3 :: (atom(), host(), ip_port()) ->
{ip_address(), atom()}).
@@ -224,6 +226,13 @@ connection_info(Pid, Items) -> rabbit_reader:info(Pid, Items).
connection_info_all() -> cmap(fun (Q) -> connection_info(Q) end).
connection_info_all(Items) -> cmap(fun (Q) -> connection_info(Q, Items) end).
+close_connection(Pid, Explanation) ->
+ case lists:any(fun ({_, ChildPid, _, _}) -> ChildPid =:= Pid end,
+ supervisor:which_children(rabbit_tcp_client_sup)) of
+ true -> rabbit_reader:shutdown(Pid, Explanation);
+ false -> throw({error, {not_a_connection_pid, Pid}})
+ end.
+
%%--------------------------------------------------------------------
tcp_host({0,0,0,0}) ->