[SSHD-786] Clients can't authenticate after unexpected exception in Nio2Acceptor


Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/06303815
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/06303815
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/06303815

Branch: refs/heads/master
Commit: 0630381505daa5ec8731d42217485a5998c9b05b
Parents: 94369e0
Author: Goldstein Lyor <[email protected]>
Authored: Thu Dec 7 09:02:35 2017 +0200
Committer: Lyor Goldstein <[email protected]>
Committed: Tue Dec 19 19:18:36 2017 +0200

----------------------------------------------------------------------
 .../org/apache/sshd/common/io/nio2/Nio2Acceptor.java   | 13 +++++++++++--
 .../apache/sshd/common/auth/AuthenticationTest.java    | 12 ++++++++----
 2 files changed, 19 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/06303815/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Acceptor.java
----------------------------------------------------------------------
diff --git 
a/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Acceptor.java 
b/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Acceptor.java
index ce86aaf..c047f21 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Acceptor.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Acceptor.java
@@ -245,8 +245,17 @@ public class Nio2Acceptor extends Nio2Service implements 
IoAcceptor {
 
             log.warn("Caught " + exc.getClass().getSimpleName()
                    + " while accepting incoming connection from " + address
-                   + ": " + exc.getMessage(),
-                    exc);
+                   + ": " + exc.getMessage(), exc);
+
+            try {
+                // Accept new connections
+                socket.accept(address, this);
+            } catch (Throwable t) {
+                // Do not call failed(t, address) to avoid infinite recursion
+                log.error("Failed (" + t.getClass().getSimpleName()
+                    + " to re-accept new connections on " + address
+                    + ": " + t.getMessage(), t);
+            }
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/06303815/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java
----------------------------------------------------------------------
diff --git 
a/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java 
b/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java
index 5e0333b..0f99de0 100644
--- 
a/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java
+++ 
b/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java
@@ -515,8 +515,8 @@ public class AuthenticationTest extends BaseTestSupport {
     @Test   // see SSHD-600
     public void testAuthExceptionPropagation() throws Exception {
         try (SshClient client = setupTestClient()) {
-            final RuntimeException expected = new RuntimeException("Synthetic 
exception");
-            final AtomicInteger invocations = new AtomicInteger(0);
+            RuntimeException expected = new RuntimeException("Synthetic 
exception");
+            AtomicInteger invocations = new AtomicInteger(0);
             client.addSessionListener(new SessionListener() {
                 @Override
                 public void sessionEvent(Session session, Event event) {
@@ -533,11 +533,15 @@ public class AuthenticationTest extends BaseTestSupport {
                 assertTrue("Failed to complete auth in allocated time", 
future.await(11L, TimeUnit.SECONDS));
                 assertFalse("Unexpected authentication success", 
future.isSuccess());
 
-                Throwable actual = future.getException();
+                Throwable signalled = future.getException();
+                Throwable actual = signalled;
                 if (actual instanceof IOException) {
                     actual = actual.getCause();
                 }
-                assertSame("Mismatched authentication failure reason", 
expected, actual);
+
+                if (expected != actual) {
+                    fail("Mismatched authentication failure reason: 
signalled=" + signalled + ", actual=" + actual);
+                }
             } finally {
                 client.stop();
             }

Reply via email to