sshnet / sshnet/SSH.NET

Connection Abort on Key Auth causes problem on reconnect

Abierto
#557 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
C#
Estrellas
4.4k
Forks
993
Merge medio
9 d 21 h
PR fusionados (30 d)
1

Descripción

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;
            }
        }

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza rastreando BaseClient.Dispose y Disconnect a través de ConnectionInfo, Session.Connect y KeyboardInteractiveAuthenticationMethod.Authenticate, centrándote en la ruta de inicio de sesión abortado que se muestra en el stack trace. Comprueba cómo se conservan los controladores de eventos de autenticación y el estado de la conexión después de un aborto. Se considera terminado cuando desechar o volver a conectar después de un intento fallido de autenticación por teclado no produce eventos obsoletos ni errores client-is-not-connected.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
csharp
Área
networking
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.