window service with ssh.net crash session operation has timed out and not running
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 4.4k
- Forks
- 993
- Avg merge
- 9d 21h
- Merged PRs (30d)
- 1
Description
I created window service that use SSH.net to read file from sFTP server every 600 seconds in OnStart I create timer
timer = new Timer(TimerCallback, null, 0, timeDelay);
and TimerCallBack is function that use SSH.net. In connection before read file I have code to connect to sFTP server like below
var FILE_READ_FLAG = false;
try
{
req = new SftpClient(ftpHost, ftpLogin, ftpLoginPassword);
req.Connect();
if (req.IsConnected)
{
directories = req.ListDirectory(ftpPath);
FILE_READ_FLAG = true;
}
}
catch (Exception e)
{
EventLog.WriteEntry(sSource,"ERROR : " + GetFullMessageFromException(e),
EventLogEntryType.Information, 234);
FILE_READ_FLAG = false;
}
if (FILE_READ_FLAG){
// read file and insert to database
}
the problem is when service run and exception occur the service can run again every 600 seconds but with the error
Session operation has timed out
at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle, TimeSpan timeout)
at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle)
at Renci.SshNet.Session.Connect()
at Renci.SshNet.BaseClient.Connect()
the service cannot run again and when I try to stop and restart service, Windows show alert message cannot stop in timely fashion and I have to kill service by cmd and start it manually
My question is why another exception can handle with try/catch block but with this error the service not run again with timer what I missing or using it wrong? thank you
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the TimerCallback and the SftpClient.Connect() call described in the report, then trace the Session.WaitOnHandle timeout in the provided stack trace. Reproduce the Windows service behavior around the 600-second timer and determine whether the reported failure is in SSH.NET or the service lifecycle; done requires a clear cause and a reproducible case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100