ssh_sftp connection problem

Jakob Cederlund jakob@REDACTED
Thu Jun 15 13:18:28 CEST 2006


Thanks for the patch! Test-case added for the connect of unknown host... 
Will check other ssh-modules too...
/Jakob

Dmitriy Kargapolov wrote:
> 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