SshOperationTimeoutException trying to start a service on remote server via C# app

Jan 22, 2015 at 3:51 PM
I am running several commands in sequence (each command is a separate ssh session) to install a service on RH/CentOS (5 and 6) via openssh and the last command to start the service seems to always timeout, regardless of which timeout value (it always reaches the timeout). Here are the basics:

rpm -i <package>
the following commands are running a batch script (provided with service)
accept EULA
set License key
start daemon (via init script)

SSH Operation timed out with 'Renci.SshNet.Common.SshOperationTimeoutException: Command '/etc/init.d/<daemon> start 2>&1' has timed out. at Renci.SshNet.SshCommand.WaitOnHandle(WaitHandle waitHandle) at Renci.SshNet.SshCommand.EndExecute(IAsyncResult asyncResult)

I saw a couple threads regarding the WaitOnHandle hanging? But wasn't too clear on the resolution, or if there is one. I can run the commands from a local shell and not encounter the timeout (which is currently set to 90s). I haven't got to the point of debugging yet, so I am just handling it as the daemon does get started. The remote server logs indicate the service gets started and takes only a couple seconds (also in my manual testing). Just checking to see if this is a known issue since I don't have a ton of time to track it down.

Thanks a ton, this library is quite useful.


Here is the code:
using (SshClient client = new SshClient(GetConnectionInfo(thisServer)))
                if (timeoutInSeconds > 0)
                    client.ConnectionInfo.Timeout = TimeSpan.FromSeconds(timeoutInSeconds);


                var command = client.CreateCommand(cmdLine);
                command.CommandTimeout = TimeSpan.FromSeconds(timeoutInSeconds);

                cmdOutput = String.IsNullOrEmpty(command.Error) ? command.Result : command.Error;

                Log.Verbose("ExecuteCmd('{0}')", cmdLine);
                Log.Verbose("  --  return code: '{0}'", command.ExitStatus);
                Log.Verbose("  -- standard out: '{0}'", string.IsNullOrEmpty(command.Result) ? "" : command.Result);
                Log.Verbose("  -- standard err: '{0}'", string.IsNullOrEmpty(command.Error) ? "" : command.Error);

                return command.ExitStatus;
Jan 23, 2015 at 8:19 AM
I don't think it's a problem in
Can you reproduce this behaviour with plink (
Usage: plink [options] [user@]host [command]
where command is your service start command.
May 13, 2015 at 10:00 PM
Ok, so I may have some more insight to this issue (finally), if you have a moment to confirm or deny what I am seeing/assuming:

Most of my commands run a command and exit without spawning any child processes, but when attempting to start a daemon via init or running a script that loops infinitely, I seem to run into this timeout issue. The assumption is the child process is attached to the SSH session via stdin/stdout/stderr and since the process is a daemon, it won't be stopping on its own, thus we never end the session and the timeout occurs. Does that jive at all? If it does, is there a mechanism to avoid this? I have seen a few things online on how to redirect stdout/stderr away from the session for a long running script:, but those things will suppress the ability to get good return codes and command output.