sshnet / sshnet/SSH.NET

window service with ssh.net crash session operation has timed out and not running

Offen
#694 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
C#
Sterne
4.4k
Forks
993
Ø Merge
9 T. 21 Std.
Gemergte PRs (30 T.)
1

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem im Bericht beschriebenen TimerCallback und dem Aufruf von SftpClient.Connect(), und verfolge dann das Timeout von Session.WaitOnHandle im bereitgestellten Stacktrace. Reproduziere das Verhalten des Windows-Dienstes im Zusammenhang mit dem 600-Sekunden-Timer und ermittle, ob der gemeldete Fehler in SSH.NET oder im Lebenszyklus des Dienstes liegt; abgeschlossen ist die Aufgabe erst, wenn eine eindeutige Ursache und ein reproduzierbarer Fall vorliegen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
csharp
Bereich
networking
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
20/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.