ssh_sftp connection problem

Dmitriy Kargapolov dmitry.kargapolov@REDACTED
Sat May 6 00:17:51 CEST 2006


Dmitriy Kargapolov wrote:
> Hi,
> I found that in ssh-0.9.1 ssh_sftp:connect/2,3 hangs in case when remote 
> host is unknown. Supposedly it happens because:
> 
> 1) internal ssh_cm:connect() call is implemented using 
> gen_server:start_link:
> connect(Host, Port, Opts) ->
>     gen_server:start_link(?MODULE, [client, self(), Host, Port, Opts], []).
> 2) when ssh_cm:init() failed because of lookup/connect timeout, parent 
> linked process is died as well, i.e. ssh_sftp:init() is died.
> 
> 3) call call ssh_cm:connect() never ends, and calling process hangs.
> 
> To test just run ssh_sftp:connect(unexisting_host,[]).
> 

Not sure if the whole ssh_sftp server needs to be linked with ssh_cm, 
but at least for the initialization phase it's better to catch exit 
signal. Following patch solved problem mentioned above.

Index: ssh_sftp.erl
===================================================================
--- ssh_sftp.erl
+++ ssh_sftp.erl
@@ -284,8 +284,10 @@
  	    {stop, Error }
      end;
  init([Host,Port,Opts]) ->
+    SaveFlag = process_flag(trap_exit, true),
      case ssh_xfer:connect(Host, Port, Opts) of
  	{ok, Xf, RBuf} ->
+	    process_flag(trap_exit, SaveFlag),
  	    {ok, #state { req_id = 0, xf = Xf, rep_buf=RBuf }};
  	Error ->
  	    {stop, Error}



More information about the erlang-questions mailing list