aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Cornish <[email protected]>2014-10-24 22:58:24 -0700
committerSimon Cornish <[email protected]>2014-10-24 22:58:24 -0700
commitc854951a2bae920f4c1e4fd4073bc2ac69d5a3a9 (patch)
tree13b87a7f0cf6e419a8e45f6e209df4b67c44a98f
parent8304aeb0114e61e8f694a58cf9e91a00856c3fe5 (diff)
downloadotp-c854951a2bae920f4c1e4fd4073bc2ac69d5a3a9.tar.gz
otp-c854951a2bae920f4c1e4fd4073bc2ac69d5a3a9.tar.bz2
otp-c854951a2bae920f4c1e4fd4073bc2ac69d5a3a9.zip
Fix ssh_sftp:start_channel timeout
The {timeout, Timeout} option passed to ssh_sftp:start_channel is not applied to the early phases of the SSH protocol. For example, if the remote server fails to respond after the "hello" then the call will hang for as long as the server keeps the TCP connection alive. This patch passes the Timeout through to ssh:connect. In case the timeout occurs during these phases, {error, timeout} is returned.
-rw-r--r--lib/ssh/src/ssh_sftp.erl2
-rw-r--r--lib/ssh/src/ssh_xfer.erl9
2 files changed, 9 insertions, 2 deletions
diff --git a/lib/ssh/src/ssh_sftp.erl b/lib/ssh/src/ssh_sftp.erl
index 721146c509..12479e9121 100644
--- a/lib/ssh/src/ssh_sftp.erl
+++ b/lib/ssh/src/ssh_sftp.erl
@@ -112,7 +112,7 @@ start_channel(Host, Opts) ->
start_channel(Host, Port, Opts) ->
{SshOpts, SftpOpts} = handle_options(Opts, [], []),
Timeout = proplists:get_value(timeout, SftpOpts, infinity),
- case ssh_xfer:connect(Host, Port, SshOpts) of
+ case ssh_xfer:connect(Host, Port, SshOpts, Timeout) of
{ok, ChannelId, Cm} ->
case ssh_channel:start(Cm, ChannelId, ?MODULE, [Cm,
ChannelId, SftpOpts]) of
diff --git a/lib/ssh/src/ssh_xfer.erl b/lib/ssh/src/ssh_xfer.erl
index 1881392db8..2743b704f1 100644
--- a/lib/ssh/src/ssh_xfer.erl
+++ b/lib/ssh/src/ssh_xfer.erl
@@ -23,7 +23,7 @@
-module(ssh_xfer).
--export([attach/2, connect/3]).
+-export([attach/2, connect/3, connect/4]).
-export([open/6, opendir/3, readdir/3, close/3, read/5, write/5,
rename/5, remove/3, mkdir/4, rmdir/3, realpath/3, extended/4,
stat/4, fstat/4, lstat/4, setstat/4,
@@ -58,6 +58,13 @@ connect(Host, Port, Opts) ->
Error -> Error
end.
+connect(Host, Port, Opts, Timeout) ->
+ case ssh:connect(Host, Port, Opts, Timeout) of
+ {ok, CM} -> open_xfer(CM, [{timeout, Timeout}|Opts]);
+ {error, Timeout} -> {error, timeout};
+ Error -> Error
+ end.
+
open_xfer(CM, Opts) ->
TMO = proplists:get_value(timeout, Opts, infinity),
case ssh_connection:session_channel(CM, ?XFER_WINDOW_SIZE, ?XFER_PACKET_SIZE, TMO) of