sshnet / sshnet/SSH.NET

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

Aperta
#694 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
C#
Stelle
4.4k
Fork
993
Merge medio
9g 21h
PR unite (30g)
1

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con il TimerCallback e la chiamata a SftpClient.Connect() descritti nel report, quindi segui il timeout di Session.WaitOnHandle nello stack trace fornito. Riproduci il comportamento del servizio Windows relativo al timer di 600 secondi e determina se il problema segnalato si trova in SSH.NET o nel ciclo di vita del servizio; il lavoro è completato quando sono disponibili una causa chiara e un caso riproducibile.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp
Ambito
networking
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
20/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.