[erlang-patches] ssh-3.0, ssh_connection_handler.erl Incorrect processing shutdown

Alexander Demidenko alex.demidenko@REDACTED
Thu Jan 23 09:49:13 CET 2014


Hello, friends!

ssh-3.0 (and below) has the following bug:
If we have a lot of SSH sessions, we will be much more timeout. (4 seconds
per each instance).

When trying to complete the ssh-application, process, was created by a call
ssh_connection_handler:init/1, receives a message of the form {'EXIT', Pid,
shutdown}. After receiving this message, will been completed a series of
calls ssh_connetion_handler:terminate, which ends the call
ssh_connetion_handler:terminate_subsystem/1->ssh_system_sup:stop_subsystem/2
. At the end of the chain calls the supervisor:which_children (SystemSup).
In this place there is a deadlock, because SystemSup process awaits the
completion message.  Since SystemSup not receive the completion message, it
completes them forcibly by timeout (after 4 second)

How can I see, in the ssh_connection_handler.erl module, invalid method
terminate by initiative supervisor. In case of shutdown, we must not call
terminate_subsytem/1

Suggest a patch that fixes this problem :

--- src/ssh_connection_handler.erl
+++ src/ssh_connection_handler.erl
@@ -904,26 +904,31 @@
                 socket = Socket}) ->
     terminate_subsytem(Connection),
     (catch Transport:close(Socket)),
     ok;

 %% Terminated by supervisor
-terminate(shutdown, StateName, #state{ssh_params = Ssh0} = State) ->
+terminate(shutdown, _StateName, #state{ssh_params = Ssh0,
+                                       transport_cb = Transport,
+                           socket = Socket} = State) ->
     DisconnectMsg =
     #ssh_msg_disconnect{code = ?SSH_DISCONNECT_BY_APPLICATION,
                 description = "Application shutdown",
                 language = "en"},
-    {SshPacket, Ssh} = ssh_transport:ssh_packet(DisconnectMsg, Ssh0),
+    {SshPacket, _Ssh} = ssh_transport:ssh_packet(DisconnectMsg, Ssh0),
     send_msg(SshPacket, State),
-    terminate(normal, StateName, State#state{ssh_params = Ssh});
+    (catch Transport:close(Socket)),
+    ok;

 terminate({shutdown, #ssh_msg_disconnect{} = Msg}, StateName,
       #state{ssh_params = Ssh0} = State) ->
      {SshPacket, Ssh} = ssh_transport:ssh_packet(Msg, Ssh0),
     send_msg(SshPacket, State),


-- 
---------------------------------------------
With best regards,
Alexander.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-patches/attachments/20140123/b3872e7c/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ssh_3.patch
Type: text/x-patch
Size: 1126 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-patches/attachments/20140123/b3872e7c/attachment.bin>


More information about the erlang-patches mailing list