You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by GitBox <gi...@apache.org> on 2020/08/07 00:18:36 UTC

[GitHub] [mina-sshd] gnodet commented on pull request #156: [SSHD-1050] Fixed race condition in AuthFuture if exception caught before authentication started

gnodet commented on pull request #156:
URL: https://github.com/apache/mina-sshd/pull/156#issuecomment-670253433


   What about using something like the following instead of multiple fields to store the exception ?
   ```
   diff --git a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java
   index 21e0631d..4037f23a 100644
   --- a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java
   +++ b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSessionImpl.java
   @@ -86,7 +86,6 @@ public class ClientSessionImpl extends AbstractClientSession {
            }
   
            authFuture = new DefaultAuthFuture(ioSession.getRemoteAddress(), futureLock);
   -        authFuture.setAuthed(false);
   
            signalSessionCreated(ioSession);
   
   @@ -124,9 +123,17 @@ public class ClientSessionImpl extends AbstractClientSession {
            ClientUserAuthService authService = getUserAuthService();
            synchronized (sessionLock) {
                String serviceName = nextServiceName();
   -            authFuture = ValidateUtils.checkNotNull(
   +            AuthFuture future = ValidateUtils.checkNotNull(
                        authService.auth(serviceName), "No auth future generated by service=%s", serviceName);
   -            return authFuture;
   +            future.addListener(f -> {
   +                Throwable e = f.getException();
   +                if (e != null) {
   +                    this.authFuture.setException(e);
   +                } else {
   +                    this.authFuture.setAuthed(f.isSuccess());
   +                }
   +            });
   +            return this.authFuture;
            }
        }
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org