From 1b8334a74501d94ec527a23a239ac3dbe09decd0 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Fri, 5 Feb 2010 15:24:53 +0000 Subject: handle attempt to close connection with a non-connection pid which was previously hanging at best and causing things to explode at worst --- src/rabbit_control.erl | 2 +- src/rabbit_networking.erl | 11 ++++++++++- 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}) -> -- cgit v1.2.1