You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2015/06/23 12:27:50 UTC

mina-sshd git commit: [SSHD-502] Review all await() calls and replace them with (configurable) timeouts

Repository: mina-sshd
Updated Branches:
  refs/heads/master 8a16e8cc8 -> 0a4447a3d


[SSHD-502] Review all await() calls and replace them with (configurable) timeouts


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

Branch: refs/heads/master
Commit: 0a4447a3da213580b0cc08bd759b455b96d2026a
Parents: 8a16e8c
Author: Lyor Goldstein <lg...@vmware.com>
Authored: Tue Jun 23 13:27:36 2015 +0300
Committer: Lyor Goldstein <lg...@vmware.com>
Committed: Tue Jun 23 13:27:36 2015 +0300

----------------------------------------------------------------------
 .../org/apache/sshd/agent/SshAgentServer.java   |  9 ++++
 .../sshd/agent/local/AgentServerProxy.java      |  7 +--
 .../sshd/agent/unix/AgentServerProxy.java       | 23 +++++----
 .../sshd/agent/unix/UnixAgentFactory.java       |  9 ++--
 .../java/org/apache/sshd/client/SshClient.java  |  5 +-
 .../client/kex/AbstractDHClientKeyExchange.java | 11 ++---
 .../org/apache/sshd/client/kex/DHGClient.java   |  5 +-
 .../org/apache/sshd/client/kex/DHGEXClient.java | 11 +++--
 .../sshd/client/scp/AbstractScpClient.java      | 36 ++++++++++++++
 .../sshd/client/scp/DefaultScpClient.java       | 18 ++-----
 .../org/apache/sshd/client/scp/ScpClient.java   | 10 ++++
 .../client/session/ClientConnectionService.java |  9 ++--
 .../sshd/client/sftp/DefaultSftpClient.java     |  3 +-
 .../org/apache/sshd/client/sftp/SftpClient.java | 10 ++++
 .../client/sftp/SftpFileSystemProvider.java     | 19 +++++---
 .../common/channel/ChannelPipedInputStream.java |  2 +-
 .../common/kex/dh/AbstractDHKeyExchange.java    | 16 ++++--
 .../session/AbstractConnectionService.java      | 51 ++++++++++++--------
 .../sshd/server/x11/X11ForwardSupport.java      | 28 +++++++----
 .../org/apache/sshd/AuthenticationTest.java     | 13 +++--
 .../java/org/apache/sshd/KeepAliveTest.java     |  4 +-
 .../src/test/java/org/apache/sshd/LoadTest.java |  2 +-
 .../org/apache/sshd/PortForwardingTest.java     |  2 +-
 .../apache/sshd/SinglePublicKeyAuthTest.java    |  3 +-
 .../java/org/apache/sshd/agent/AgentTest.java   |  4 +-
 .../java/org/apache/sshd/client/ClientTest.java |  6 +--
 .../org/apache/sshd/client/kex/KexTest.java     |  2 +-
 .../sshd/deprecated/AbstractUserAuth.java       |  6 +--
 .../deprecated/UserAuthKeyboardInteractive.java |  4 +-
 .../sshd/deprecated/UserAuthPassword.java       |  4 +-
 .../sshd/deprecated/UserAuthPublicKey.java      |  4 +-
 .../java/org/apache/sshd/server/ServerTest.java |  8 +--
 .../git/transport/GitSshdSessionFactory.java    | 32 ++++++++++--
 .../apache/sshd/git/pgm/GitPgmCommandTest.java  |  3 +-
 34 files changed, 253 insertions(+), 126 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/main/java/org/apache/sshd/agent/SshAgentServer.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/SshAgentServer.java b/sshd-core/src/main/java/org/apache/sshd/agent/SshAgentServer.java
index d07a6f7..256140b 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/SshAgentServer.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/SshAgentServer.java
@@ -19,10 +19,19 @@
 package org.apache.sshd.agent;
 
 import java.nio.channels.Channel;
+import java.util.concurrent.TimeUnit;
 
 public interface SshAgentServer extends Channel {
     /**
      * @return Agent server identifier
      */
     String getId();
+    
+    /**
+     * Value that can be set on the {@link org.apache.sshd.common.FactoryManager}
+     * to configure the channel open timeout value (millis). If not specified
+     * then {@link #DEFAULT_CHANNEL_OPEN_TIMEOUT} value is used
+     */
+    String CHANNEL_OPEN_TIMEOUT_PROP = "ssh-agent-server-channel-open-timeout";
+        long DEFAULT_CHANNEL_OPEN_TIMEOUT = TimeUnit.SECONDS.toMillis(30L);
 }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/main/java/org/apache/sshd/agent/local/AgentServerProxy.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/local/AgentServerProxy.java b/sshd-core/src/main/java/org/apache/sshd/agent/local/AgentServerProxy.java
index 7a6d5a6..81885bb 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/local/AgentServerProxy.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/local/AgentServerProxy.java
@@ -25,6 +25,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import org.apache.sshd.agent.SshAgent;
 import org.apache.sshd.agent.SshAgentServer;
 import org.apache.sshd.client.future.OpenFuture;
+import org.apache.sshd.common.FactoryManagerUtils;
 import org.apache.sshd.common.session.ConnectionService;
 import org.apache.sshd.common.util.GenericUtils;
 import org.apache.sshd.common.util.ValidateUtils;
@@ -47,11 +48,7 @@ public class AgentServerProxy extends AbstractLoggingBean implements SshAgentSer
         try {
             AgentForwardedChannel channel = new AgentForwardedChannel();
             this.service.registerChannel(channel);
-            OpenFuture future = channel.open().await();
-            Throwable t = future.getException();
-            if (t != null) {
-                throw t;
-            }
+            channel.open().verify(FactoryManagerUtils.getLongProperty(this.service.getSession(), CHANNEL_OPEN_TIMEOUT_PROP, DEFAULT_CHANNEL_OPEN_TIMEOUT));
             return channel.getAgent();
         } catch(Throwable t) {
             if (log.isDebugEnabled()) {

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentServerProxy.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentServerProxy.java b/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentServerProxy.java
index 1b02795..235263f 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentServerProxy.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentServerProxy.java
@@ -26,9 +26,10 @@ import java.util.concurrent.Future;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.sshd.agent.SshAgentServer;
-import org.apache.sshd.client.future.OpenFuture;
+import org.apache.sshd.common.FactoryManagerUtils;
 import org.apache.sshd.common.SshException;
 import org.apache.sshd.common.session.ConnectionService;
+import org.apache.sshd.common.session.Session;
 import org.apache.sshd.common.util.GenericUtils;
 import org.apache.sshd.common.util.OsUtils;
 import org.apache.sshd.common.util.logging.AbstractLoggingBean;
@@ -43,6 +44,14 @@ import org.apache.tomcat.jni.Status;
  * The server side fake agent, acting as an agent, but actually forwarding the requests to the auth channel on the client side.
  */
 public class AgentServerProxy extends AbstractLoggingBean implements SshAgentServer, ExecutorServiceCarrier {
+    /**
+     * Property that can be set on the {@link Session} in order to control
+     * the authentication timeout (millis). If not specified then
+     * {@link #DEFAULT_AUTH_SOCKET_TIMEOUT} is used
+     */
+    public static final String AUTH_SOCKET_TIMEOUT = "ssh-agent-server-proxy-auth-socket-timeout";
+        public static final int DEFAULT_AUTH_SOCKET_TIMEOUT = 10000000;
+
     private final ConnectionService service;
     private final String authSocket;
     private final long pool;
@@ -93,16 +102,12 @@ public class AgentServerProxy extends AbstractLoggingBean implements SshAgentSer
                                     if (!isOpen()) {
                                         break;
                                     }
-                                    Socket.timeoutSet(clientSock, 10000000);    // TODO allow to configure this
+
+                                    Session session = AgentServerProxy.this.service.getSession();
+                                    Socket.timeoutSet(clientSock, FactoryManagerUtils.getIntProperty(session, AUTH_SOCKET_TIMEOUT, DEFAULT_AUTH_SOCKET_TIMEOUT));
                                     AgentForwardedChannel channel = new AgentForwardedChannel(clientSock);
                                     AgentServerProxy.this.service.registerChannel(channel);
-                                    OpenFuture future = channel.open().await();
-                                    Throwable t = future.getException();
-                                    if (t instanceof Exception) {
-                                        throw (Exception) t;
-                                    } else if (t != null) {
-                                        throw new Exception(t);
-                                    }
+                                    channel.open().verify(FactoryManagerUtils.getLongProperty(session, CHANNEL_OPEN_TIMEOUT_PROP, DEFAULT_CHANNEL_OPEN_TIMEOUT));
                                 } catch (Exception e) {
                                     if (isOpen()) {
                                         log.info(e.getClass().getSimpleName() + " while authentication forwarding: " + e.getMessage(), e);

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/main/java/org/apache/sshd/agent/unix/UnixAgentFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/unix/UnixAgentFactory.java b/sshd-core/src/main/java/org/apache/sshd/agent/unix/UnixAgentFactory.java
index 8e74b08..c101842 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/unix/UnixAgentFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/unix/UnixAgentFactory.java
@@ -32,6 +32,7 @@ import org.apache.sshd.common.channel.Channel;
 import org.apache.sshd.common.session.ConnectionService;
 import org.apache.sshd.common.session.Session;
 import org.apache.sshd.common.util.GenericUtils;
+import org.apache.sshd.common.util.ValidateUtils;
 import org.apache.sshd.common.util.threads.ExecutorServiceConfigurer;
 import org.apache.sshd.server.session.ServerSession;
 
@@ -97,10 +98,10 @@ public class UnixAgentFactory implements SshAgentFactory, ExecutorServiceConfigu
 
     @Override
     public SshAgentServer createServer(ConnectionService service) throws IOException {
-        Session session = service.getSession();
-        if (!(session instanceof ServerSession)) {
-            throw new IllegalStateException("The session used to create an agent server proxy must be a server session");
-        }
+        Session session = ValidateUtils.checkNotNull(service.getSession(), "No session", GenericUtils.EMPTY_OBJECT_ARRAY);
+        ValidateUtils.checkTrue(session instanceof ServerSession,
+                                "The session used to create an agent server proxy must be a server session",
+                                GenericUtils.EMPTY_OBJECT_ARRAY);
         return new AgentServerProxy(service, getExecutorService(), isShutdownOnExit());
     }
 }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java b/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java
index 7df53e7..c1b70e8 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java
@@ -48,7 +48,6 @@ import org.apache.sshd.client.future.ConnectFuture;
 import org.apache.sshd.client.future.DefaultConnectFuture;
 import org.apache.sshd.client.session.ClientConnectionService;
 import org.apache.sshd.client.session.ClientSession;
-import org.apache.sshd.client.session.ClientSessionImpl;
 import org.apache.sshd.client.session.ClientUserAuthService;
 import org.apache.sshd.common.AbstractFactoryManager;
 import org.apache.sshd.common.Closeable;
@@ -271,7 +270,7 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
                 } else if (future.getException() != null) {
                     connectFuture.setException(future.getException());
                 } else {
-                    ClientSessionImpl session = (ClientSessionImpl) AbstractSession.getSession(future.getSession());
+                    ClientSession session = (ClientSession) AbstractSession.getSession(future.getSession());
                     session.setUsername(username);
                     connectFuture.setSession(session);
                 }
@@ -516,7 +515,7 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
                     try {
                         channel.setOut(new NoCloseOutputStream(System.out));
                         channel.setErr(new NoCloseOutputStream(System.err));
-                        channel.open().await();
+                        channel.open().await(); // TODO use verify and a configurable timeout
                         channel.waitFor(ClientChannel.CLOSED, 0);
                     } finally {
                         channel.close();

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/main/java/org/apache/sshd/client/kex/AbstractDHClientKeyExchange.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/kex/AbstractDHClientKeyExchange.java b/sshd-core/src/main/java/org/apache/sshd/client/kex/AbstractDHClientKeyExchange.java
index f55943f..556edda 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/kex/AbstractDHClientKeyExchange.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/kex/AbstractDHClientKeyExchange.java
@@ -21,16 +21,16 @@ package org.apache.sshd.client.kex;
 
 import java.security.PublicKey;
 
-import org.apache.sshd.client.session.ClientSessionImpl;
+import org.apache.sshd.client.session.ClientSession;
 import org.apache.sshd.common.kex.dh.AbstractDHKeyExchange;
 import org.apache.sshd.common.session.AbstractSession;
+import org.apache.sshd.common.util.GenericUtils;
+import org.apache.sshd.common.util.ValidateUtils;
 
 /**
  * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
  */
 public abstract class AbstractDHClientKeyExchange extends AbstractDHKeyExchange {
-
-    protected ClientSessionImpl session;
     protected PublicKey serverKey;
 
     protected AbstractDHClientKeyExchange() {
@@ -40,10 +40,7 @@ public abstract class AbstractDHClientKeyExchange extends AbstractDHKeyExchange
     @Override
     public void init(AbstractSession s, byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C) throws Exception {
         super.init(s, V_S, V_C, I_S, I_C);
-        if (!(s instanceof ClientSessionImpl)) {
-            throw new IllegalStateException("Using a client side KeyExchange on a server");
-        }
-        session = (ClientSessionImpl) s;
+        ValidateUtils.checkTrue(s instanceof ClientSession, "Using a client side KeyExchange on a server", GenericUtils.EMPTY_OBJECT_ARRAY);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGClient.java b/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGClient.java
index 0f1c1f8..4667987 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGClient.java
@@ -27,6 +27,7 @@ import org.apache.sshd.common.kex.AbstractDH;
 import org.apache.sshd.common.kex.DHFactory;
 import org.apache.sshd.common.kex.KeyExchange;
 import org.apache.sshd.common.session.AbstractSession;
+import org.apache.sshd.common.session.Session;
 import org.apache.sshd.common.signature.Signature;
 import org.apache.sshd.common.util.GenericUtils;
 import org.apache.sshd.common.util.ValidateUtils;
@@ -81,7 +82,8 @@ public class DHGClient extends AbstractDHClientKeyExchange {
         log.debug("Send SSH_MSG_KEXDH_INIT");
         Buffer buffer = s.createBuffer(SshConstants.SSH_MSG_KEXDH_INIT);
         buffer.putMPInt(e);
-        session.writePacket(buffer);
+        
+        s.writePacket(buffer);
     }
 
     protected AbstractDH getDH() throws Exception {
@@ -123,6 +125,7 @@ public class DHGClient extends AbstractDHClientKeyExchange {
         hash.update(buffer.array(), 0, buffer.available());
         H = hash.digest();
 
+        Session session = getSession();
         FactoryManager manager = session.getFactoryManager();
         Signature verif = ValidateUtils.checkNotNull(NamedFactory.Utils.create(manager.getSignatureFactories(), keyAlg),
                             "No verifier located for algorithm=%s",

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGEXClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGEXClient.java b/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGEXClient.java
index bd3f222..00319b8 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGEXClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGEXClient.java
@@ -21,6 +21,7 @@ package org.apache.sshd.client.kex;
 
 import java.math.BigInteger;
 
+import org.apache.sshd.common.FactoryManager;
 import org.apache.sshd.common.NamedFactory;
 import org.apache.sshd.common.SshConstants;
 import org.apache.sshd.common.SshException;
@@ -29,6 +30,7 @@ import org.apache.sshd.common.kex.AbstractDH;
 import org.apache.sshd.common.kex.DHFactory;
 import org.apache.sshd.common.kex.KeyExchange;
 import org.apache.sshd.common.session.AbstractSession;
+import org.apache.sshd.common.session.Session;
 import org.apache.sshd.common.signature.Signature;
 import org.apache.sshd.common.util.GenericUtils;
 import org.apache.sshd.common.util.ValidateUtils;
@@ -78,11 +80,11 @@ public class DHGEXClient extends AbstractDHClientKeyExchange {
     public void init(AbstractSession s, byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C) throws Exception {
         super.init(s, V_S, V_C, I_S, I_C);
         log.debug("Send SSH_MSG_KEX_DH_GEX_REQUEST");
-        Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_KEX_DH_GEX_REQUEST);
+        Buffer buffer = s.createBuffer(SshConstants.SSH_MSG_KEX_DH_GEX_REQUEST);
         buffer.putInt(min);
         buffer.putInt(prf);
         buffer.putInt(max);
-        session.writePacket(buffer);
+        s.writePacket(buffer);
 
         expected = SshConstants.SSH_MSG_KEX_DH_GEX_GROUP;
     }
@@ -106,6 +108,7 @@ public class DHGEXClient extends AbstractDHClientKeyExchange {
             e = dh.getE();
 
             log.debug("Send SSH_MSG_KEX_DH_GEX_INIT");
+            Session session = getSession();
             buffer = session.createBuffer(SshConstants.SSH_MSG_KEX_DH_GEX_INIT);
             buffer.putMPInt(e);
             session.writePacket(buffer);
@@ -145,8 +148,10 @@ public class DHGEXClient extends AbstractDHClientKeyExchange {
             hash.update(buffer.array(), 0, buffer.available());
             H = hash.digest();
 
+            Session session = getSession();
+            FactoryManager manager = session.getFactoryManager();
             Signature verif = ValidateUtils.checkNotNull(
-                    NamedFactory.Utils.create(session.getFactoryManager().getSignatureFactories(), keyAlg),
+                    NamedFactory.Utils.create(manager.getSignatureFactories(), keyAlg),
                     "No verifier located for algorithm=%s",
                     keyAlg);
             verif.initVerifier(serverKey);

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/main/java/org/apache/sshd/client/scp/AbstractScpClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/scp/AbstractScpClient.java b/sshd-core/src/main/java/org/apache/sshd/client/scp/AbstractScpClient.java
index fcefa3e..5871171 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/scp/AbstractScpClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/scp/AbstractScpClient.java
@@ -32,7 +32,12 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.EnumSet;
+import java.util.concurrent.TimeUnit;
 
+import org.apache.sshd.client.channel.ChannelExec;
+import org.apache.sshd.client.session.ClientSession;
+import org.apache.sshd.common.FactoryManager;
+import org.apache.sshd.common.FactoryManagerUtils;
 import org.apache.sshd.common.SshException;
 import org.apache.sshd.common.scp.ScpHelper;
 import org.apache.sshd.common.scp.ScpTimestamp;
@@ -210,6 +215,37 @@ public abstract class AbstractScpClient extends AbstractLoggingBean implements S
         return options;
     }
 
+    protected ChannelExec openCommandChannel(ClientSession session, String cmd) throws IOException {
+        FactoryManager manager = ValidateUtils.checkNotNull(session, "No session for command: %s", cmd).getFactoryManager();
+        long waitTimeout = FactoryManagerUtils.getLongProperty(manager, SCP_EXEC_CHANNEL_OPEN_TIMEOUT, DEFAULT_EXEC_CHANNEL_OPEN_TIMEOUT);
+        ChannelExec channel = session.createExecChannel(cmd);
+
+        long startTime = System.nanoTime();
+        try {
+            channel.open().verify(waitTimeout);
+            long endTime = System.nanoTime(), nanosWait = endTime - startTime;
+            if (log.isTraceEnabled()) {
+                log.trace("openCommandChannel(" + session + ")[" + cmd + "]"
+                        + " completed after " + nanosWait
+                        + " nanos out of " + TimeUnit.MILLISECONDS.toNanos(waitTimeout));
+            }
+
+            return channel;
+        } catch(IOException | RuntimeException e) {
+            long endTime = System.nanoTime(), nanosWait = endTime - startTime; 
+            if (log.isTraceEnabled()) {
+                log.trace("openCommandChannel(" + session + ")[" + cmd + "]"
+                        + " failed (" + e.getClass().getSimpleName() + ")"
+                        + " to complete after " + nanosWait
+                        + " nanos out of " + TimeUnit.MILLISECONDS.toNanos(waitTimeout)
+                        + ": " + e.getMessage());
+            }
+
+            channel.close(false);
+            throw e;
+        }
+    }
+
     public static String createSendCommand(String remote, Collection<Option> options) {
         StringBuilder sb = new StringBuilder(remote.length() + Long.SIZE).append(ScpHelper.SCP_COMMAND_PREFIX);
         if (options.contains(Option.Recursive)) {

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/main/java/org/apache/sshd/client/scp/DefaultScpClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/scp/DefaultScpClient.java b/sshd-core/src/main/java/org/apache/sshd/client/scp/DefaultScpClient.java
index 15ca7cb..6d4fdf9 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/scp/DefaultScpClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/scp/DefaultScpClient.java
@@ -79,10 +79,8 @@ public class DefaultScpClient extends AbstractScpClient {
     @Override
     public void download(String remote, OutputStream local) throws IOException {
         String cmd = createReceiveCommand(remote, Collections.<Option>emptyList());
-        ChannelExec channel = clientSession.createExecChannel(cmd);
+        ChannelExec channel = openCommandChannel(clientSession, cmd);
         try {
-            channel.open().await(); // TODO use verify + configurable timeout
-
             // NOTE: we use a mock file system since we expect no invocations for it
             ScpHelper helper = new ScpHelper(channel.getInvertedOut(), channel.getInvertedIn(), new MockFileSystem(remote), listener);
             helper.receiveFileStream(local, ScpHelper.DEFAULT_RECEIVE_BUFFER_SIZE);
@@ -94,10 +92,8 @@ public class DefaultScpClient extends AbstractScpClient {
     @Override
     protected void download(String remote, FileSystem fs, Path local, Collection<Option> options) throws IOException {
         String cmd = createReceiveCommand(remote, options);
-        ChannelExec channel = clientSession.createExecChannel(cmd);
+        ChannelExec channel = openCommandChannel(clientSession, cmd);
         try {
-            channel.open().await(); // TODO use verify + configurable timeout
-
             ScpHelper helper = new ScpHelper(channel.getInvertedOut(), channel.getInvertedIn(), fs, listener);
             helper.receive(local,
                            options.contains(Option.Recursive),
@@ -117,9 +113,7 @@ public class DefaultScpClient extends AbstractScpClient {
                           : ValidateUtils.checkNotNullAndNotEmpty(remote.substring(namePos + 1), "No name value in remote=%s", remote)
                           ;
         final String cmd = createSendCommand(remote, (time != null) ? EnumSet.of(Option.PreserveAttributes) : Collections.<Option>emptySet());
-        ChannelExec channel = clientSession.createExecChannel(cmd);
-        channel.open().await();   // TODO use verify + configurable timeout
-
+        ChannelExec channel = openCommandChannel(clientSession, cmd);
         try {
             ScpHelper helper = new ScpHelper(channel.getInvertedOut(), channel.getInvertedIn(), new MockFileSystem(remote), listener);
             final Path mockPath = new MockPath(remote);
@@ -172,11 +166,9 @@ public class DefaultScpClient extends AbstractScpClient {
         if (local.size() > 1) {
             options = addTargetIsDirectory(options);
         }
-        
-        String cmd = createSendCommand(remote, options);
-        ChannelExec channel = clientSession.createExecChannel(cmd);
-        channel.open().await();    // TODO use verify + configurable timeout
 
+        String cmd = createSendCommand(remote, options);
+        ChannelExec channel = openCommandChannel(clientSession, cmd);
         try {
             FactoryManager manager = clientSession.getFactoryManager();
             FileSystemFactory factory = manager.getFileSystemFactory();

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/main/java/org/apache/sshd/client/scp/ScpClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/scp/ScpClient.java b/sshd-core/src/main/java/org/apache/sshd/client/scp/ScpClient.java
index ae7bb1e..7db1d64 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/scp/ScpClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/scp/ScpClient.java
@@ -24,6 +24,7 @@ import java.io.OutputStream;
 import java.nio.file.Path;
 import java.nio.file.attribute.PosixFilePermission;
 import java.util.Collection;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.sshd.common.scp.ScpTimestamp;
 
@@ -37,6 +38,15 @@ public interface ScpClient {
         TargetIsDirectory
     }
 
+    /**
+     * Configurable value of the {@link org.apache.sshd.common.FactoryManager}
+     * for controlling the wait timeout for opening a channel for an SCP command
+     * in milliseconds. If not specified, then {@link #DEFAULT_EXEC_CHANNEL_OPEN_TIMEOUT}
+     * value is used
+     */
+    String SCP_EXEC_CHANNEL_OPEN_TIMEOUT = "scp-exec-channel-open-timeout";
+        long DEFAULT_EXEC_CHANNEL_OPEN_TIMEOUT = TimeUnit.SECONDS.toMillis(30L);
+
     void download(String remote, String local, Option... options) throws IOException;
     void download(String remote, String local, Collection<Option> options) throws IOException;
 

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java
index 1ff7cb3..b3ec2d1 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java
@@ -31,6 +31,8 @@ import org.apache.sshd.common.SshConstants;
 import org.apache.sshd.common.SshException;
 import org.apache.sshd.common.session.AbstractConnectionService;
 import org.apache.sshd.common.session.Session;
+import org.apache.sshd.common.util.GenericUtils;
+import org.apache.sshd.common.util.ValidateUtils;
 import org.apache.sshd.common.util.buffer.Buffer;
 
 /**
@@ -58,14 +60,13 @@ public class ClientConnectionService extends AbstractConnectionService {
 
     public ClientConnectionService(Session s) throws SshException {
         super(s);
-        if (!(s instanceof ClientSessionImpl)) {
-            throw new IllegalStateException("Client side service used on server side");
-        }
+
+        ValidateUtils.checkTrue(s instanceof ClientSession, "Client side service used on server side", GenericUtils.EMPTY_OBJECT_ARRAY);
     }
 
     @Override
     public void start() {
-        if (!((ClientSessionImpl) session).isAuthenticated()) {
+        if (!((ClientSession) session).isAuthenticated()) {
             throw new IllegalStateException("Session is not authenticated");
         }
         startHeartBeat();

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/main/java/org/apache/sshd/client/sftp/DefaultSftpClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/sftp/DefaultSftpClient.java b/sshd-core/src/main/java/org/apache/sshd/client/sftp/DefaultSftpClient.java
index e810ffb..6b58c36 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/sftp/DefaultSftpClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/sftp/DefaultSftpClient.java
@@ -106,6 +106,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 import org.apache.sshd.client.SftpException;
 import org.apache.sshd.client.channel.ChannelSubsystem;
 import org.apache.sshd.client.session.ClientSession;
+import org.apache.sshd.common.FactoryManagerUtils;
 import org.apache.sshd.common.SshException;
 import org.apache.sshd.common.sftp.SftpConstants;
 import org.apache.sshd.common.util.GenericUtils;
@@ -145,7 +146,7 @@ public class DefaultSftpClient extends AbstractSftpClient {
             }
         });
         this.channel.setErr(new ByteArrayOutputStream(Byte.MAX_VALUE));
-        this.channel.open().await();       // TODO use verify + configurable timeout
+        this.channel.open().verify(FactoryManagerUtils.getLongProperty(clientSession, SFTP_CHANNEL_OPEN_TIMEOUT, DEFAULT_CHANNEL_OPEN_TIMEOUT));
         this.channel.onClose(new Runnable() {
             @SuppressWarnings("synthetic-access")
             @Override

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpClient.java b/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpClient.java
index ada3f48..739a408 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpClient.java
@@ -281,6 +281,16 @@ public interface SftpClient extends Closeable {
     // default values used if none specified
     int MIN_BUFFER_SIZE=Byte.MAX_VALUE, MIN_READ_BUFFER_SIZE=MIN_BUFFER_SIZE, MIN_WRITE_BUFFER_SIZE=MIN_BUFFER_SIZE;
     int IO_BUFFER_SIZE=32 * 1024, DEFAULT_READ_BUFFER_SIZE=IO_BUFFER_SIZE, DEFAULT_WRITE_BUFFER_SIZE=IO_BUFFER_SIZE;
+    long DEFAULT_WAIT_TIMEOUT=TimeUnit.SECONDS.toMillis(30L);
+
+    /**
+     * Property that can be used on the {@link org.apache.sshd.common.FactoryManager}
+     * to control the internal timeout used by the client to open a channel.
+     * If not specified then {@link #DEFAULT_CHANNEL_OPEN_TIMEOUT} value
+     * is used
+     */
+    String SFTP_CHANNEL_OPEN_TIMEOUT = "sftp-channel-open-timeout";
+        long DEFAULT_CHANNEL_OPEN_TIMEOUT = DEFAULT_WAIT_TIMEOUT;
 
     InputStream read(String path) throws IOException;
     InputStream read(String path, int bufferSize) throws IOException;

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpFileSystemProvider.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpFileSystemProvider.java b/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpFileSystemProvider.java
index 4c041bd..2ac72b1 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpFileSystemProvider.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/sftp/SftpFileSystemProvider.java
@@ -31,7 +31,6 @@ import static org.apache.sshd.common.sftp.SftpConstants.S_IXUSR;
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.InterruptedIOException;
 import java.io.OutputStream;
 import java.net.URI;
 import java.nio.channels.FileChannel;
@@ -89,7 +88,12 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class SftpFileSystemProvider extends FileSystemProvider {
-    public static final String  READ_BUFFER_PROP_NAME = "read-buffer-size", WRITE_BUFFER_PROP_NAME="write-buffer-size";
+    public static final String READ_BUFFER_PROP_NAME = "sftp-fs-read-buffer-size";
+        public static final int DEFAULT_READ_BUFFER_SIZE = SftpClient.DEFAULT_READ_BUFFER_SIZE;
+    public static final String WRITE_BUFFER_PROP_NAME = "sftp-fs-write-buffer-size";
+        public static final int DEFAULT_WRITE_BUFFER_SIZE = SftpClient.DEFAULT_WRITE_BUFFER_SIZE;
+    public static final String CONNECT_TIME_PROP_NAME = "sftp-fs-connect-time";
+        public static final long DEFAULT_CONNECT_TIME = SftpClient.DEFAULT_WAIT_TIMEOUT;
 
     private final SshClient client;
     private final Map<String, SftpFileSystem> fileSystems = new HashMap<String, SftpFileSystem>();
@@ -132,12 +136,15 @@ public class SftpFileSystemProvider extends FileSystemProvider {
 
             ClientSession session=null;
             try {
-                session = client.connect(ui[0], host, port).await().getSession();
+                session = client.connect(ui[0], host, port)
+                                .verify(FactoryManagerUtils.getLongProperty(env, CONNECT_TIME_PROP_NAME, DEFAULT_CONNECT_TIME))
+                                .getSession()
+                                ;
                 session.addPasswordIdentity(ui[1]);
                 session.auth().verify();
                 fileSystem = new SftpFileSystem(this, session);
-                fileSystem.setReadBufferSize(FactoryManagerUtils.getIntProperty(env, READ_BUFFER_PROP_NAME, SftpClient.DEFAULT_READ_BUFFER_SIZE));
-                fileSystem.setWriteBufferSize(FactoryManagerUtils.getIntProperty(env, WRITE_BUFFER_PROP_NAME, SftpClient.DEFAULT_WRITE_BUFFER_SIZE));
+                fileSystem.setReadBufferSize(FactoryManagerUtils.getIntProperty(env, READ_BUFFER_PROP_NAME, DEFAULT_READ_BUFFER_SIZE));
+                fileSystem.setWriteBufferSize(FactoryManagerUtils.getIntProperty(env, WRITE_BUFFER_PROP_NAME, DEFAULT_WRITE_BUFFER_SIZE));
                 fileSystems.put(authority, fileSystem);
                 return fileSystem;
             } catch(Exception e) {
@@ -156,8 +163,6 @@ public class SftpFileSystemProvider extends FileSystemProvider {
                 
                 if (e instanceof IOException) {
                     throw (IOException) e;
-                } else if (e instanceof InterruptedException) {
-                    throw (IOException) new InterruptedIOException("Interrupted while waiting for connection to " + host + ":" + port).initCause(e);
                 } else if (e instanceof RuntimeException) {
                     throw (RuntimeException) e;
                 } else {

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelPipedInputStream.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelPipedInputStream.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelPipedInputStream.java
index 44a4d8d..1f0f86e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelPipedInputStream.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelPipedInputStream.java
@@ -40,7 +40,7 @@ import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
  * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
  */
 public class ChannelPipedInputStream extends InputStream implements ChannelPipedSink {
-    public static final long DEFAULT_TIMEOUT = 0;    // infinite
+    public static final long DEFAULT_TIMEOUT = 0L;
 
     private final Window localWindow;
     private final Buffer buffer = new ByteArrayBuffer();

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/main/java/org/apache/sshd/common/kex/dh/AbstractDHKeyExchange.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/kex/dh/AbstractDHKeyExchange.java b/sshd-core/src/main/java/org/apache/sshd/common/kex/dh/AbstractDHKeyExchange.java
index 67078b0..e43be6e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/kex/dh/AbstractDHKeyExchange.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/kex/dh/AbstractDHKeyExchange.java
@@ -22,12 +22,15 @@ package org.apache.sshd.common.kex.dh;
 import org.apache.sshd.common.digest.Digest;
 import org.apache.sshd.common.kex.KeyExchange;
 import org.apache.sshd.common.session.AbstractSession;
+import org.apache.sshd.common.util.GenericUtils;
+import org.apache.sshd.common.util.ValidateUtils;
 import org.apache.sshd.common.util.logging.AbstractLoggingBean;
 
 /**
  * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
  */
 public abstract class AbstractDHKeyExchange extends AbstractLoggingBean implements KeyExchange {
+    private AbstractSession session;
     protected byte[] V_S;
     protected byte[] V_C;
     protected byte[] I_S;
@@ -44,10 +47,15 @@ public abstract class AbstractDHKeyExchange extends AbstractLoggingBean implemen
 
     @Override
     public void init(AbstractSession s, byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C) throws Exception {
-        this.V_S = V_S;
-        this.V_C = V_C;
-        this.I_S = I_S;
-        this.I_C = I_C;
+        this.session = ValidateUtils.checkNotNull(s, "No session", GenericUtils.EMPTY_OBJECT_ARRAY);
+        this.V_S = ValidateUtils.checkNotNullAndNotEmpty(V_S, "No V_S value", GenericUtils.EMPTY_OBJECT_ARRAY);
+        this.V_C = ValidateUtils.checkNotNullAndNotEmpty(V_C, "No V_C value", GenericUtils.EMPTY_OBJECT_ARRAY);
+        this.I_S = ValidateUtils.checkNotNullAndNotEmpty(I_S, "No I_S value", GenericUtils.EMPTY_OBJECT_ARRAY);
+        this.I_C = ValidateUtils.checkNotNullAndNotEmpty(I_C, "No I_C value", GenericUtils.EMPTY_OBJECT_ARRAY);
+    }
+
+    public AbstractSession getSession() {
+        return session;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java b/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java
index dc6cba8..ab52948 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractConnectionService.java
@@ -18,6 +18,20 @@
  */
 package org.apache.sshd.common.session;
 
+import static org.apache.sshd.common.SshConstants.SSH_MSG_CHANNEL_CLOSE;
+import static org.apache.sshd.common.SshConstants.SSH_MSG_CHANNEL_DATA;
+import static org.apache.sshd.common.SshConstants.SSH_MSG_CHANNEL_EOF;
+import static org.apache.sshd.common.SshConstants.SSH_MSG_CHANNEL_EXTENDED_DATA;
+import static org.apache.sshd.common.SshConstants.SSH_MSG_CHANNEL_FAILURE;
+import static org.apache.sshd.common.SshConstants.SSH_MSG_CHANNEL_OPEN;
+import static org.apache.sshd.common.SshConstants.SSH_MSG_CHANNEL_OPEN_CONFIRMATION;
+import static org.apache.sshd.common.SshConstants.SSH_MSG_CHANNEL_OPEN_FAILURE;
+import static org.apache.sshd.common.SshConstants.SSH_MSG_CHANNEL_REQUEST;
+import static org.apache.sshd.common.SshConstants.SSH_MSG_CHANNEL_WINDOW_ADJUST;
+import static org.apache.sshd.common.SshConstants.SSH_MSG_GLOBAL_REQUEST;
+import static org.apache.sshd.common.SshConstants.SSH_MSG_REQUEST_FAILURE;
+import static org.apache.sshd.common.SshConstants.SSH_MSG_REQUEST_SUCCESS;
+
 import java.io.IOException;
 import java.util.Collection;
 import java.util.List;
@@ -29,32 +43,22 @@ import org.apache.sshd.agent.common.AgentForwardSupport;
 import org.apache.sshd.client.channel.AbstractClientChannel;
 import org.apache.sshd.client.future.OpenFuture;
 import org.apache.sshd.common.Closeable;
+import org.apache.sshd.common.FactoryManager;
 import org.apache.sshd.common.NamedFactory;
 import org.apache.sshd.common.SshConstants;
 import org.apache.sshd.common.SshException;
 import org.apache.sshd.common.channel.Channel;
 import org.apache.sshd.common.channel.RequestHandler;
 import org.apache.sshd.common.forward.TcpipForwarder;
+import org.apache.sshd.common.forward.TcpipForwarderFactory;
 import org.apache.sshd.common.future.SshFutureListener;
 import org.apache.sshd.common.util.CloseableUtils;
+import org.apache.sshd.common.util.GenericUtils;
+import org.apache.sshd.common.util.ValidateUtils;
 import org.apache.sshd.common.util.buffer.Buffer;
 import org.apache.sshd.server.channel.OpenChannelException;
 import org.apache.sshd.server.x11.X11ForwardSupport;
 
-import static org.apache.sshd.common.SshConstants.SSH_MSG_CHANNEL_CLOSE;
-import static org.apache.sshd.common.SshConstants.SSH_MSG_CHANNEL_DATA;
-import static org.apache.sshd.common.SshConstants.SSH_MSG_CHANNEL_EOF;
-import static org.apache.sshd.common.SshConstants.SSH_MSG_CHANNEL_EXTENDED_DATA;
-import static org.apache.sshd.common.SshConstants.SSH_MSG_CHANNEL_FAILURE;
-import static org.apache.sshd.common.SshConstants.SSH_MSG_CHANNEL_OPEN;
-import static org.apache.sshd.common.SshConstants.SSH_MSG_CHANNEL_OPEN_CONFIRMATION;
-import static org.apache.sshd.common.SshConstants.SSH_MSG_CHANNEL_OPEN_FAILURE;
-import static org.apache.sshd.common.SshConstants.SSH_MSG_CHANNEL_REQUEST;
-import static org.apache.sshd.common.SshConstants.SSH_MSG_CHANNEL_WINDOW_ADJUST;
-import static org.apache.sshd.common.SshConstants.SSH_MSG_GLOBAL_REQUEST;
-import static org.apache.sshd.common.SshConstants.SSH_MSG_REQUEST_FAILURE;
-import static org.apache.sshd.common.SshConstants.SSH_MSG_REQUEST_SUCCESS;
-
 /**
  * Base implementation of ConnectionService.
  *
@@ -67,7 +71,7 @@ public abstract class AbstractConnectionService extends CloseableUtils.AbstractI
     /** Next channel identifier */
     protected final AtomicInteger nextChannelId = new AtomicInteger(0);
 
-    protected final Session session;
+    protected final AbstractSession session;
 
     /** The tcpip forwarder */
     protected final TcpipForwarder tcpipForwarder;
@@ -76,10 +80,17 @@ public abstract class AbstractConnectionService extends CloseableUtils.AbstractI
     protected boolean allowMoreSessions = true;
 
     protected AbstractConnectionService(Session session) {
-        this.session = session;
+        ValidateUtils.checkTrue(session instanceof AbstractSession, "Not an AbstractSession", GenericUtils.EMPTY_OBJECT_ARRAY);
+        this.session = (AbstractSession) session;
+        FactoryManager manager = session.getFactoryManager();
         agentForward = new AgentForwardSupport(this);
         x11Forward = new X11ForwardSupport(this);
-        tcpipForwarder = session.getFactoryManager().getTcpipForwarderFactory().create(this);
+        
+        TcpipForwarderFactory factory = ValidateUtils.checkNotNull(
+                manager.getTcpipForwarderFactory(),
+                "No forwarder factory",
+                GenericUtils.EMPTY_OBJECT_ARRAY);
+        tcpipForwarder = factory.create(this);
     }
 
     public Collection<Channel> getChannels() {
@@ -88,7 +99,7 @@ public abstract class AbstractConnectionService extends CloseableUtils.AbstractI
 
     @Override
     public AbstractSession getSession() {
-        return (AbstractSession) session;
+        return session;
     }
 
     @Override
@@ -438,11 +449,11 @@ public abstract class AbstractConnectionService extends CloseableUtils.AbstractI
     }
 
     protected void requestSuccess(Buffer buffer) throws Exception {
-        ((AbstractSession) session).requestSuccess(buffer);
+        session.requestSuccess(buffer);
     }
 
     protected void requestFailure(Buffer buffer) throws Exception {
-        ((AbstractSession) session).requestFailure(buffer);
+        session.requestFailure(buffer);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/main/java/org/apache/sshd/server/x11/X11ForwardSupport.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/x11/X11ForwardSupport.java b/sshd-core/src/main/java/org/apache/sshd/server/x11/X11ForwardSupport.java
index cff5849..f574a97 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/x11/X11ForwardSupport.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/x11/X11ForwardSupport.java
@@ -21,20 +21,27 @@ package org.apache.sshd.server.x11;
 import java.io.IOException;
 import java.net.BindException;
 import java.net.InetSocketAddress;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.sshd.client.channel.AbstractClientChannel;
 import org.apache.sshd.client.future.DefaultOpenFuture;
 import org.apache.sshd.client.future.OpenFuture;
 import org.apache.sshd.common.Closeable;
+import org.apache.sshd.common.FactoryManager;
+import org.apache.sshd.common.FactoryManagerUtils;
 import org.apache.sshd.common.SshConstants;
 import org.apache.sshd.common.SshException;
 import org.apache.sshd.common.channel.ChannelOutputStream;
 import org.apache.sshd.common.io.IoAcceptor;
 import org.apache.sshd.common.io.IoHandler;
+import org.apache.sshd.common.io.IoServiceFactory;
 import org.apache.sshd.common.io.IoSession;
 import org.apache.sshd.common.session.ConnectionService;
+import org.apache.sshd.common.session.Session;
 import org.apache.sshd.common.util.CloseableUtils;
+import org.apache.sshd.common.util.GenericUtils;
 import org.apache.sshd.common.util.Readable;
+import org.apache.sshd.common.util.ValidateUtils;
 import org.apache.sshd.common.util.buffer.Buffer;
 import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
 
@@ -44,6 +51,13 @@ import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
 public class X11ForwardSupport extends CloseableUtils.AbstractInnerCloseable implements IoHandler {
 
     private static String xauthCommand = System.getProperty("sshd.xauthCommand", "xauth");
+    /**
+     * Configuration value on the {@link FactoryManager} to control the
+     * channel open timeout. If not specified then {@link #DEFAULT_CHANNEL_OPEN_TIMEOUT}
+     * value is used
+     */
+    public static final String CHANNEL_OPEN_TIMEOUT_PROP = "x11-fwd-open-timeout";
+        public static final long DEFAULT_CHANNEL_OPEN_TIMEOUT = TimeUnit.SECONDS.toMillis(30L);
 
     public static final int X11_DISPLAY_OFFSET = 10;
     public static final int MAX_DISPLAYS = 1000;
@@ -57,7 +71,6 @@ public class X11ForwardSupport extends CloseableUtils.AbstractInnerCloseable imp
     private IoAcceptor acceptor;
 
     public X11ForwardSupport(ConnectionService service) {
-        super();
         this.service = service;
     }
 
@@ -83,7 +96,10 @@ public class X11ForwardSupport extends CloseableUtils.AbstractInnerCloseable imp
         }
 
         if (acceptor == null) {
-            acceptor = service.getSession().getFactoryManager().getIoServiceFactory().createAcceptor(this);
+            Session session = ValidateUtils.checkNotNull(service.getSession(), "No session", GenericUtils.EMPTY_OBJECT_ARRAY);
+            FactoryManager manager = ValidateUtils.checkNotNull(session.getFactoryManager(), "No factory manager", GenericUtils.EMPTY_OBJECT_ARRAY);
+            IoServiceFactory factory = ValidateUtils.checkNotNull(manager.getIoServiceFactory(), "No I/O service factory", GenericUtils.EMPTY_OBJECT_ARRAY);
+            acceptor = factory.createAcceptor(this);
         }
 
         int displayNumber, port;
@@ -134,13 +150,7 @@ public class X11ForwardSupport extends CloseableUtils.AbstractInnerCloseable imp
         ChannelForwardedX11 channel = new ChannelForwardedX11(session);
         session.setAttribute(ChannelForwardedX11.class, channel);
         this.service.registerChannel(channel);
-        OpenFuture future = channel.open().await();
-        Throwable t = future.getException();
-        if (t instanceof Exception) {
-            throw (Exception) t;
-        } else if (t != null) {
-            throw new Exception(t);
-        }
+        channel.open().verify(FactoryManagerUtils.getLongProperty(this.service.getSession(), CHANNEL_OPEN_TIMEOUT_PROP, DEFAULT_CHANNEL_OPEN_TIMEOUT));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/test/java/org/apache/sshd/AuthenticationTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/AuthenticationTest.java b/sshd-core/src/test/java/org/apache/sshd/AuthenticationTest.java
index 4c1029a..e02e436 100644
--- a/sshd-core/src/test/java/org/apache/sshd/AuthenticationTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/AuthenticationTest.java
@@ -27,7 +27,6 @@ import org.apache.sshd.client.SshClient;
 import org.apache.sshd.client.future.AuthFuture;
 import org.apache.sshd.client.session.ClientConnectionService;
 import org.apache.sshd.client.session.ClientSession;
-import org.apache.sshd.client.session.ClientSessionImpl;
 import org.apache.sshd.common.FactoryManagerUtils;
 import org.apache.sshd.common.io.IoSession;
 import org.apache.sshd.common.keyprovider.KeyPairProvider;
@@ -188,21 +187,21 @@ public class AuthenticationTest extends BaseTestSupport {
     }
 
     private AuthFuture authPassword(ClientSession s, String user, String pswd) throws IOException {
-        ((ClientSessionImpl) s).setUsername(user);
+        s.setUsername(user);
         return s.getService(ClientUserAuthServiceOld.class)
-                .auth(new UserAuthPassword((ClientSessionImpl) s, "ssh-connection", pswd));
+                .auth(new UserAuthPassword(s, "ssh-connection", pswd));
     }
 
     private AuthFuture authInteractive(ClientSession s, String user, String pswd) throws IOException {
-        ((ClientSessionImpl) s).setUsername(user);
+        s.setUsername(user);
         return s.getService(ClientUserAuthServiceOld.class)
-                .auth(new UserAuthKeyboardInteractive((ClientSessionImpl) s, "ssh-connection", pswd));
+                .auth(new UserAuthKeyboardInteractive(s, "ssh-connection", pswd));
     }
 
     private AuthFuture authPublicKey(ClientSession s, String user, KeyPair pair) throws IOException {
-        ((ClientSessionImpl) s).setUsername(user);
+        s.setUsername(user);
         return s.getService(ClientUserAuthServiceOld.class)
-                .auth(new UserAuthPublicKey((ClientSessionImpl) s, "ssh-connection", pair));
+                .auth(new UserAuthPublicKey(s, "ssh-connection", pair));
     }
 
     public static class TestSession extends ServerSessionImpl {

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/test/java/org/apache/sshd/KeepAliveTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/KeepAliveTest.java b/sshd-core/src/test/java/org/apache/sshd/KeepAliveTest.java
index edb1047..2940f37 100644
--- a/sshd-core/src/test/java/org/apache/sshd/KeepAliveTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/KeepAliveTest.java
@@ -174,7 +174,7 @@ public class KeepAliveTest extends BaseTestSupport {
 
                 channel.setOut(out);
                 channel.setErr(err);
-                channel.open().await();
+                channel.open().verify(9L, TimeUnit.SECONDS);
         
                 assertTrue("Latch time out", TestEchoShellFactory.TestEchoShell.latch.await(10L, TimeUnit.SECONDS));
                 int state = channel.waitFor(ClientChannel.CLOSED, WAIT);
@@ -204,7 +204,7 @@ public class KeepAliveTest extends BaseTestSupport {
 
                 channel.setOut(out);
                 channel.setErr(err);
-                channel.open().await();
+                channel.open().verify(9L, TimeUnit.SECONDS);
     
                 assertTrue("Latch time out", TestEchoShellFactory.TestEchoShell.latch.await(10L, TimeUnit.SECONDS));
                 int state = channel.waitFor(ClientChannel.CLOSED, WAIT);

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/test/java/org/apache/sshd/LoadTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/LoadTest.java b/sshd-core/src/test/java/org/apache/sshd/LoadTest.java
index 26a6b2a..c8ab9c3 100644
--- a/sshd-core/src/test/java/org/apache/sshd/LoadTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/LoadTest.java
@@ -138,7 +138,7 @@ public class LoadTest extends BaseTestSupport {
                     channel.setErr(err);
 
                     try {
-                        channel.open().await();
+                        channel.open().verify(9L, TimeUnit.SECONDS);
                         try(OutputStream pipedIn = channel.getInvertedIn()) {
                             msg += "\nexit\n";
                             pipedIn.write(msg.getBytes());

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/test/java/org/apache/sshd/PortForwardingTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/PortForwardingTest.java b/sshd-core/src/test/java/org/apache/sshd/PortForwardingTest.java
index 65bd93f..c56fd40 100644
--- a/sshd-core/src/test/java/org/apache/sshd/PortForwardingTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/PortForwardingTest.java
@@ -357,7 +357,7 @@ public class PortForwardingTest extends BaseTestSupport {
             SshdSocketAddress remote = new SshdSocketAddress("localhost", echoPort);
 
             try(ChannelDirectTcpip channel = session.createDirectTcpipChannel(local, remote)) {
-                channel.open().await();
+                channel.open().verify(9L, TimeUnit.SECONDS);
 
                 String  expected = getCurrentTestName();
                 byte[]  bytes = expected.getBytes();

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/test/java/org/apache/sshd/SinglePublicKeyAuthTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/SinglePublicKeyAuthTest.java b/sshd-core/src/test/java/org/apache/sshd/SinglePublicKeyAuthTest.java
index 1a5fa21..11e97be 100644
--- a/sshd-core/src/test/java/org/apache/sshd/SinglePublicKeyAuthTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/SinglePublicKeyAuthTest.java
@@ -117,7 +117,8 @@ public class SinglePublicKeyAuthTest extends BaseTestSupport {
             try(ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
                 session.addPublicKeyIdentity(pairRsaBad);
                 session.addPublicKeyIdentity(pairRsa);
-                assertTrue(session.auth().await().isSuccess());
+                session.auth().verify(5L, TimeUnit.SECONDS);
+
                 assertEquals(2, count.size());
                 assertTrue(count.containsKey(KeyUtils.getFingerPrint(pairRsaBad.getPublic())));
                 assertTrue(count.containsKey(KeyUtils.getFingerPrint(pairRsa.getPublic())));

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/test/java/org/apache/sshd/agent/AgentTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/agent/AgentTest.java b/sshd-core/src/test/java/org/apache/sshd/agent/AgentTest.java
index b74ebd2..78b3911 100644
--- a/sshd-core/src/test/java/org/apache/sshd/agent/AgentTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/agent/AgentTest.java
@@ -141,7 +141,7 @@ public class AgentTest extends BaseTestSupport {
                             channel1.setOut(out);
                             channel1.setErr(err);
                             channel1.setAgentForwarding(true);
-                            channel1.open().await();
+                            channel1.open().verify(9L, TimeUnit.SECONDS);
                             
                             try(OutputStream pipedIn = channel1.getInvertedIn()) {
                                 synchronized (shellFactory.shell) {
@@ -164,7 +164,7 @@ public class AgentTest extends BaseTestSupport {
                                             channel2.setOut(shellFactory.shell.getOut());
                                             channel2.setErr(shellFactory.shell.getErr());
                                             channel2.setAgentForwarding(true);
-                                            channel2.open().await();
+                                            channel2.open().verify(9L, TimeUnit.SECONDS);
                                     
                                             pipedIn.write("foo\n".getBytes());
                                             pipedIn.flush();

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java b/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
index 438e870..d85ff14 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
@@ -374,7 +374,7 @@ public class ClientTest extends BaseTestSupport {
 
                 channel.setOut(out);
                 channel.setErr(err);
-                channel.open().await();
+                channel.open().verify(9L, TimeUnit.SECONDS);
         
                 try(OutputStream pipedIn = new TeeOutputStream(sent, channel.getInvertedIn())) {
                     pipedIn.write("this is my command\n".getBytes());
@@ -494,7 +494,7 @@ public class ClientTest extends BaseTestSupport {
                 channel.setIn(inPipe);
                 channel.setOut(out);
                 channel.setErr(err);
-                channel.open().await();
+                channel.open().verify(9L, TimeUnit.SECONDS);
         
         
                 int bytes = 0;
@@ -855,7 +855,7 @@ public class ClientTest extends BaseTestSupport {
                     channel.setIn(inPipe);
                     channel.setOut(out);
                     channel.setErr(err);
-                    channel.open().await();
+                    channel.open().verify(9L, TimeUnit.SECONDS);
         
         //            ((AbstractSession) session).disconnect(SshConstants.SSH2_DISCONNECT_BY_APPLICATION, "Cancel");
                     AbstractSession cs = (AbstractSession) session;

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java b/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java
index e3286d7..8f2f9d8 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java
@@ -127,7 +127,7 @@ public class KexTest extends BaseTestSupport {
                         channel.setIn(inPipe);
                         channel.setOut(out);
                         channel.setErr(err);
-                        assertTrue("Channel not opened", channel.open().await().isOpened());
+                        channel.open().verify(9L, TimeUnit.SECONDS);
             
                         teeOut.write("this is my command\n".getBytes());
                         teeOut.flush();

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/test/java/org/apache/sshd/deprecated/AbstractUserAuth.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/deprecated/AbstractUserAuth.java b/sshd-core/src/test/java/org/apache/sshd/deprecated/AbstractUserAuth.java
index 3cbd5a4..8f501f2 100644
--- a/sshd-core/src/test/java/org/apache/sshd/deprecated/AbstractUserAuth.java
+++ b/sshd-core/src/test/java/org/apache/sshd/deprecated/AbstractUserAuth.java
@@ -18,16 +18,16 @@
  */
 package org.apache.sshd.deprecated;
 
-import org.apache.sshd.client.session.ClientSessionImpl;
+import org.apache.sshd.client.session.ClientSession;
 import org.apache.sshd.common.util.logging.AbstractLoggingBean;
 
 /**
  */
 public abstract class AbstractUserAuth extends AbstractLoggingBean implements UserAuth {
-    protected final ClientSessionImpl session;
+    protected final ClientSession session;
     protected final String service;
 
-    protected AbstractUserAuth(ClientSessionImpl session, String service) {
+    protected AbstractUserAuth(ClientSession session, String service) {
         this.session = session;
         this.service = service;
     }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthKeyboardInteractive.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthKeyboardInteractive.java b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthKeyboardInteractive.java
index 918db97..5e41bd7 100644
--- a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthKeyboardInteractive.java
+++ b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthKeyboardInteractive.java
@@ -27,7 +27,7 @@ import java.io.IOException;
 import java.util.Arrays;
 
 import org.apache.sshd.client.UserInteraction;
-import org.apache.sshd.client.session.ClientSessionImpl;
+import org.apache.sshd.client.session.ClientSession;
 import org.apache.sshd.common.SshConstants;
 import org.apache.sshd.common.util.buffer.Buffer;
 
@@ -41,7 +41,7 @@ public class UserAuthKeyboardInteractive extends AbstractUserAuth {
 
     private final String password;
 
-    public UserAuthKeyboardInteractive(ClientSessionImpl session, String service, String password) {
+    public UserAuthKeyboardInteractive(ClientSession session, String service, String password) {
         super(session, service);
         this.password = password;
     }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPassword.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPassword.java b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPassword.java
index 4d6fbd5..4dde6cc 100644
--- a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPassword.java
+++ b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPassword.java
@@ -20,7 +20,7 @@ package org.apache.sshd.deprecated;
 
 import java.io.IOException;
 
-import org.apache.sshd.client.session.ClientSessionImpl;
+import org.apache.sshd.client.session.ClientSession;
 import org.apache.sshd.common.SshConstants;
 import org.apache.sshd.common.util.buffer.Buffer;
 
@@ -32,7 +32,7 @@ import org.apache.sshd.common.util.buffer.Buffer;
 public class UserAuthPassword extends AbstractUserAuth {
     private final String password;
 
-    public UserAuthPassword(ClientSessionImpl session, String service, String password) {
+    public UserAuthPassword(ClientSession session, String service, String password) {
         super(session, service);
         this.password = password;
     }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPublicKey.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPublicKey.java b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPublicKey.java
index f4d1a96..1a3fb72 100644
--- a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPublicKey.java
+++ b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPublicKey.java
@@ -22,7 +22,7 @@ import java.io.IOException;
 import java.security.KeyPair;
 
 import org.apache.sshd.client.auth.UserAuthPublicKey.UserAuthPublicKeyFactory;
-import org.apache.sshd.client.session.ClientSessionImpl;
+import org.apache.sshd.client.session.ClientSession;
 import org.apache.sshd.common.FactoryManager;
 import org.apache.sshd.common.NamedFactory;
 import org.apache.sshd.common.SshConstants;
@@ -40,7 +40,7 @@ import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
 public class UserAuthPublicKey extends AbstractUserAuth {
     private final KeyPair key;
 
-    public UserAuthPublicKey(ClientSessionImpl session, String service, KeyPair key) {
+    public UserAuthPublicKey(ClientSession session, String service, KeyPair key) {
         super(session, service);
         this.key = key;
     }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java b/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java
index 60d9d9a..2c43d77 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java
@@ -123,7 +123,8 @@ public class ServerTest extends BaseTestSupport {
             while ((res & ClientSession.CLOSED) == 0) {
                 nbTrials ++;
                 s.getService(ClientUserAuthServiceOld.class)
-                        .auth(new UserAuthPassword((ClientSessionImpl) s, "ssh-connection", "buggy"));
+                 .auth(new UserAuthPassword(s, "ssh-connection", "buggy"))
+                 ;
                 res = s.waitFor(ClientSession.CLOSED | ClientSession.WAIT_AUTH, 5000);
                 if (res == ClientSession.TIMEOUT) {
                     throw new TimeoutException();
@@ -153,7 +154,8 @@ public class ServerTest extends BaseTestSupport {
                 nbTrials++;
                 assertTrue(nbTrials < 100);
                 authFuture = s.getService(ClientUserAuthServiceOld.class)
-                        .auth(new UserAuthPassword((ClientSessionImpl) s, "ssh-connection", "buggy"));
+                              .auth(new UserAuthPassword(s, "ssh-connection", "buggy"))
+                              ;
                 assertTrue("Authentication wait failed", authFuture.await(5000));
                 assertTrue("Authentication not done", authFuture.isDone());
                 assertFalse("Authentication unexpectedly successful", authFuture.isSuccess());
@@ -215,7 +217,7 @@ public class ServerTest extends BaseTestSupport {
                 ByteArrayOutputStream err = new ByteArrayOutputStream()) {
                 shell.setOut(out);
                 shell.setErr(err);
-                shell.open().await();
+                shell.open().verify(9L, TimeUnit.SECONDS);
                 int res = s.waitFor(ClientSession.CLOSED, 2 * IDLE_TIMEOUT);
                 assertEquals("Session should be closed", ClientSession.CLOSED | ClientSession.AUTHED, res);
             }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-git/src/main/java/org/apache/sshd/git/transport/GitSshdSessionFactory.java
----------------------------------------------------------------------
diff --git a/sshd-git/src/main/java/org/apache/sshd/git/transport/GitSshdSessionFactory.java b/sshd-git/src/main/java/org/apache/sshd/git/transport/GitSshdSessionFactory.java
index 2894d1b..f14b0fb 100644
--- a/sshd-git/src/main/java/org/apache/sshd/git/transport/GitSshdSessionFactory.java
+++ b/sshd-git/src/main/java/org/apache/sshd/git/transport/GitSshdSessionFactory.java
@@ -21,11 +21,14 @@ package org.apache.sshd.git.transport;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.sshd.client.SshClient;
 import org.apache.sshd.client.channel.ChannelExec;
 import org.apache.sshd.client.channel.ClientChannel;
 import org.apache.sshd.client.session.ClientSession;
+import org.apache.sshd.common.FactoryManager;
+import org.apache.sshd.common.FactoryManagerUtils;
 import org.apache.sshd.common.util.GenericUtils;
 import org.apache.sshd.common.util.ValidateUtils;
 import org.eclipse.jgit.errors.TransportException;
@@ -42,6 +45,25 @@ import org.eclipse.jgit.util.FS;
  * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
  */
 public class GitSshdSessionFactory extends SshSessionFactory {
+    /**
+     * Property used to configure the SSHD {@link FactoryManager} with
+     * the default timeout (millis) to connect to the remote SSH server.
+     * If not specified then {@link #DEFAULT_CONNECT_TIMEOUT} is used
+     */
+    public static final String CONNECT_TIMEOUT_PROP = "git-ssh-connect-timeout";
+        public static final long DEFAULT_CONNECT_TIMEOUT = TimeUnit.SECONDS.toMillis(30L);
+
+    /**
+     * Property used to configure the SSHD {@link FactoryManager} with
+     * the default timeout (millis) to authenticate with the remote SSH server.
+     * If not specified then {@link #DEFAULT_AUTH_TIMEOUT} is used
+     */
+    public static final String AUTH_TIMEOUT_PROP = "git-ssh-connect-timeout";
+        public static final long DEFAULT_AUTH_TIMEOUT = TimeUnit.SECONDS.toMillis(15L);
+
+    public GitSshdSessionFactory() {
+        super();
+    }
 
     @Override
     public RemoteSession getSession(URIish uri, CredentialsProvider credentialsProvider, FS fs, int tms) throws TransportException {
@@ -57,7 +79,6 @@ public class GitSshdSessionFactory extends SshSessionFactory {
     }
 
     public class SshdSession implements RemoteSession {
-
         private final SshClient client;
         private final ClientSession session;
 
@@ -82,16 +103,19 @@ public class GitSshdSessionFactory extends SshSessionFactory {
             }
 
             client = createClient();
+
             client.start();
-            session = client.connect(user, host, port).await().getSession();
+            session = client.connect(user, host, port)
+                            .verify(FactoryManagerUtils.getLongProperty(client, CONNECT_TIMEOUT_PROP, DEFAULT_CONNECT_TIMEOUT))
+                            .getSession()
+                            ;
             if (pass != null) {
                 session.addPasswordIdentity(pass);
             }
             if (pass2 != null) {
                 session.addPasswordIdentity(new String(pass2));
             }
-            session.auth().verify();
-
+            session.auth().verify(FactoryManagerUtils.getLongProperty(client, AUTH_TIMEOUT_PROP, DEFAULT_AUTH_TIMEOUT);
         }
 
         @Override

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0a4447a3/sshd-git/src/test/java/org/apache/sshd/git/pgm/GitPgmCommandTest.java
----------------------------------------------------------------------
diff --git a/sshd-git/src/test/java/org/apache/sshd/git/pgm/GitPgmCommandTest.java b/sshd-git/src/test/java/org/apache/sshd/git/pgm/GitPgmCommandTest.java
index 15712bd..ba186fa 100644
--- a/sshd-git/src/test/java/org/apache/sshd/git/pgm/GitPgmCommandTest.java
+++ b/sshd-git/src/test/java/org/apache/sshd/git/pgm/GitPgmCommandTest.java
@@ -20,6 +20,7 @@ package org.apache.sshd.git.pgm;
 
 import java.io.File;
 import java.util.Arrays;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.sshd.client.SshClient;
 import org.apache.sshd.client.channel.ChannelExec;
@@ -67,7 +68,7 @@ public class GitPgmCommandTest {
         SshClient client = SshClient.setUpDefaultClient();
         client.start();
 
-        ClientSession session = client.connect("sshd", "localhost", 8001).await().getSession();
+        ClientSession session = client.connect("sshd", "localhost", 8001).verify(7L, TimeUnit.SECONDS).getSession();
         session.addPasswordIdentity("sshd");
         session.auth().verify();