sshnet / sshnet/SSH.NET

Connection Abort on Key Auth causes problem on reconnect

Aperta
#557 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'm using SSH.NET v2016.1.0 to connect to many UNIX servers. We have logic to retry connecting if an attempt fails. One of the servers uses keyboard authentication and intermittently aborts the connection during login. We have not found the cause of abort but that is not of concern here. When an abort occurs, the ConnectionInfo object is not being properly disposed when the client is Disconnected or Disposed. This is causing subsequent connection attempts to fail with client is not connected errors or errant events to be logged.

Renci.SshNet.Common.SshConnectionException: An established connection was aborted by the server.
at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle, TimeSpan timeout)
at Renci.SshNet.KeyboardInteractiveAuthenticationMethod.Authenticate(Session session)
at Renci.SshNet.ClientAuthentication.TryAuthenticate(ISession session, AuthenticationState authenticationState, String[] allowedAuthenticationMethods, SshAuthenticationException& authenticationException)
at Renci.SshNet.ClientAuthentication.Authenticate(IConnectionInfoInternal connectionInfo, ISession session)
at Renci.SshNet.ConnectionInfo.Authenticate(ISession session, IServiceFactory serviceFactory)
at Renci.SshNet.Session.Connect()
at Renci.SshNet.BaseClient.Connect()

We have worked around by recreating the ConnectionInfo object on each attempt and unsubscribing handlers for the AuthenticationPrompt and AuthenticationBanners events before Disposing the client when a failure occurs.

private void DisposeClient(BaseClient client)
        {
            if (client != null)
            {
                if (client.ConnectionInfo != null)
                {
                    // Unregister events
                    foreach (AuthenticationMethod authenticationMethod in client.ConnectionInfo.AuthenticationMethods)
                    {
                        if (authenticationMethod is KeyboardInteractiveAuthenticationMethod)
                        {                            
                       ((KeyboardInteractiveAuthenticationMethod)authenticationMethod).AuthenticationPrompt -= KeyboardInteractive_AuthenticationPrompt;
                            break;
                        }
                    }

                    client.ConnectionInfo.AuthenticationBanner -= ConnectionInfo_AuthenticationBanner;
                }

                client.Dispose();

                client = null;
            }
        }

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 tracciando BaseClient.Dispose e Disconnect attraverso ConnectionInfo, Session.Connect e KeyboardInteractiveAuthenticationMethod.Authenticate, concentrandoti sul percorso di accesso interrotto mostrato nello stack trace. Verifica come vengono mantenuti i gestori degli eventi di autenticazione e lo stato della connessione dopo un’interruzione. Il lavoro è completato quando la disposizione o la riconnessione dopo un tentativo di autenticazione tramite tastiera non produce eventi obsoleti né errori client-is-not-connected.

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
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.