sshnet / sshnet/SSH.NET

Timeout does not seem to have desired effect

Open
#1,697 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
4.4k
Forks
993
Avg merge
9d 21h
Merged PRs (30d)
1

Description

SSH.NET 2025.0.0

I'm executing a command on a ssh session to a router that takes some time to complete. I get a System.Exception after 30 seconds no matter what I've set timeouts to:

long_running_script.sh:

#!/bin/sh
echo Simulating a long running operation
sleep 45
echo Done

short_running_script.sh:

#!/bin/sh
echo Simulating a quick operation
sleep 5
echo Done
var sshClient = new SshClient("192.168.1.1", "root", password);
sshClient.ConnectionInfo.Timeout = TimeSpan.FromSeconds(60);
sshClient.ConnectionInfo.ChannelCloseTimeout = TimeSpan.FromSeconds(60);
sshClient.Connect();

var cmd = sshClient.CreateCommand(". /home/user/long_running_script.sh");
cmd.CommandTimeout = TimeSpan.FromSeconds(60);
var res = cmd.Execute();

This throws a generic System.Exception after 30 seconds. No further information, no inner exception. If I call short_running_script.sh instead it works fine.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with long_running_script.sh and short_running_script.sh through SshClient.CreateCommand, setting ConnectionInfo.Timeout, ChannelCloseTimeout, and CommandTimeout to 60 seconds. Trace the command execution path to determine why the long-running command fails after 30 seconds; done means the 45-second script completes without the generic exception while the 5-second script remains successful.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.