mina-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r830525 - in /mina/sshd/trunk/sshd-core/src: main/java/org/apache/sshd/SshServer.java main/java/org/apache/sshd/common/session/AbstractSession.java test/java/org/apache/sshd/PortForwardingTest.java
Date Wed, 28 Oct 2009 13:19:58 GMT
Author: gnodet
Date: Wed Oct 28 13:19:57 2009
New Revision: 830525

URL: http://svn.apache.org/viewvc?rev=830525&view=rev
Log:
SSHD43: When the ssh server is closd, channels are not closed cleanly, causing clients to
hang

Modified:
    mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/SshServer.java
    mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java
    mina/sshd/trunk/sshd-core/src/test/java/org/apache/sshd/PortForwardingTest.java

Modified: mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/SshServer.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/SshServer.java?rev=830525&r1=830524&r2=830525&view=diff
==============================================================================
--- mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/SshServer.java (original)
+++ mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/SshServer.java Wed Oct 28 13:19:57
2009
@@ -21,12 +21,15 @@
 import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.security.InvalidKeyException;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.concurrent.CountDownLatch;
 
 import org.apache.mina.core.service.IoAcceptor;
+import org.apache.mina.core.session.IoSession;
 import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
 import org.apache.sshd.common.AbstractFactoryManager;
 import org.apache.sshd.common.Channel;
@@ -42,6 +45,8 @@
 import org.apache.sshd.common.cipher.BlowfishCBC;
 import org.apache.sshd.common.cipher.TripleDESCBC;
 import org.apache.sshd.common.compression.CompressionNone;
+import org.apache.sshd.common.future.CloseFuture;
+import org.apache.sshd.common.future.SshFutureListener;
 import org.apache.sshd.common.keyprovider.FileKeyPairProvider;
 import org.apache.sshd.common.mac.HMACMD5;
 import org.apache.sshd.common.mac.HMACMD596;
@@ -50,6 +55,7 @@
 import org.apache.sshd.common.random.BouncyCastleRandom;
 import org.apache.sshd.common.random.JceRandom;
 import org.apache.sshd.common.random.SingletonRandomFactory;
+import org.apache.sshd.common.session.AbstractSession;
 import org.apache.sshd.common.signature.SignatureDSA;
 import org.apache.sshd.common.signature.SignatureRSA;
 import org.apache.sshd.common.util.SecurityUtils;
@@ -233,7 +239,26 @@
     /**
      * Stop the SSH server.  This method will block until all resources are actually disposed.
      */
-    public void stop() {
+    public void stop() throws InterruptedException {
+        acceptor.setCloseOnDeactivation(false);
+        acceptor.unbind();
+        List<AbstractSession> sessions = new ArrayList<AbstractSession>();
+        for (IoSession ioSession : acceptor.getManagedSessions().values()) {
+            AbstractSession session = AbstractSession.getSession(ioSession, true);
+            if (session != null) {
+                sessions.add(session);
+            }
+        }
+        final CountDownLatch latch = new CountDownLatch(sessions.size());
+        SshFutureListener<CloseFuture> listener = new SshFutureListener<CloseFuture>()
{
+            public void operationComplete(CloseFuture future) {
+                latch.countDown();
+            }
+        };
+        for (AbstractSession session : sessions) {
+            session.close(false).addListener(listener);
+        }
+        latch.await();
         acceptor.dispose();
         acceptor = null;
     }

Modified: mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java?rev=830525&r1=830524&r2=830525&view=diff
==============================================================================
--- mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java
(original)
+++ mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java
Wed Oct 28 13:19:57 2009
@@ -262,7 +262,7 @@
         } catch (Throwable t2) {
             // Ignore
         }
-        close(false);
+        close(true);
     }
 
     /**

Modified: mina/sshd/trunk/sshd-core/src/test/java/org/apache/sshd/PortForwardingTest.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/test/java/org/apache/sshd/PortForwardingTest.java?rev=830525&r1=830524&r2=830525&view=diff
==============================================================================
--- mina/sshd/trunk/sshd-core/src/test/java/org/apache/sshd/PortForwardingTest.java (original)
+++ mina/sshd/trunk/sshd-core/src/test/java/org/apache/sshd/PortForwardingTest.java Wed Oct
28 13:19:57 2009
@@ -197,7 +197,7 @@
         assertEquals("Hello", res);
         s.close();
 
-        session.delPortForwardingR(forwardedPort);
+        session.delPortForwardingL(forwardedPort);
 
 //        session.setPortForwardingL(8010, "www.amazon.com", 80);
 //        Thread.sleep(1000000);



Mime
View raw message