When setting a session timeout, the behaviour seems incorrect! Consider this code that connects via ssh and runs sleep 30 && echo DONE to sleep for 30 seconds:
let username = "...";
let ip = "...";
let password = "...";
let timeout_ms = 15_000;
let command = "sleep 30 && echo DONE"
let tcp = std::net::TcpStream::connect(format!("{ip}:22"))?;
let mut sess = Session::new()?;
sess.set_timeout(timeout_ms);
sess.set_tcp_stream(tcp);
sess.handshake()?;
sess.userauth_password(&username, &password)?;
if !sess.authenticated() {
return Err(anyhow!("Failed to connect by SSH"));
}
// Connect channel in exec mode.
let mut channel = sess.channel_session()?;
channel.handle_extended_data(ssh2::ExtendedData::Merge)?;
println!("running command: {command}");
channel.exec(command)?;
let mut output = String::new();
channel.read_to_string(&mut output)?;
channel.close()?;
channel.wait_close()?;
let exit_status = channel.exit_status()?;
sess.disconnect(
Some(DisconnectCode::ByApplication),
"Finished Running Script",
None,
)?;
println!("SUCCESS");
println!("exit code: {exit_status}");
println!("output:\n{output}");
I expect the session to timeout after 15 seconds, but instead it times out after 30 seconds! If instead we have timeout_ms = 5_000 then it times out after 15 seconds. From my experimenting I think the current (unexpected) behaviour is as follows:
If the command blocks for duation t and t < timeout then return Ok
If the command blocks for duation t and t > 3*timeout then return a timeout error at time 3*timeout.
If the command blocks for duation t and timeout < t < 3*timeout_ms then return a timeout error at time t
I'm running on windows and with ssh2-0.9.4
When setting a session timeout, the behaviour seems incorrect! Consider this code that connects via ssh and runs
sleep 30 && echo DONEto sleep for 30 seconds:I expect the session to timeout after 15 seconds, but instead it times out after 30 seconds! If instead we have
timeout_ms = 5_000then it times out after 15 seconds. From my experimenting I think the current (unexpected) behaviour is as follows:If the command blocks for duation
tandt < timeoutthen return OkIf the command blocks for duation
tandt > 3*timeoutthen return a timeout error at time3*timeout.If the command blocks for duation
tandtimeout < t < 3*timeout_msthen return a timeout error at timetI'm running on windows and with ssh2-0.9.4