You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by hu...@apache.org on 2014/01/03 11:18:10 UTC

[37/50] [abbrv] git commit: updated refs/heads/opendaylight to 858fb69

CLOUDSTACK-5723: Add timeout for SSL handshake

To prevent malfunction agent block the future SSL connections


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/4312f926
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/4312f926
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/4312f926

Branch: refs/heads/opendaylight
Commit: 4312f9268e8fd911950f7fc38a7a3df5306ee060
Parents: 725bed4
Author: Sheng Yang <sh...@citrix.com>
Authored: Thu Jan 2 11:33:46 2014 -0800
Committer: Sheng Yang <sh...@citrix.com>
Committed: Thu Jan 2 13:54:38 2014 -0800

----------------------------------------------------------------------
 utils/src/com/cloud/utils/nio/Link.java | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4312f926/utils/src/com/cloud/utils/nio/Link.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/nio/Link.java b/utils/src/com/cloud/utils/nio/Link.java
index dfeb9dc..9a3c619 100755
--- a/utils/src/com/cloud/utils/nio/Link.java
+++ b/utils/src/com/cloud/utils/nio/Link.java
@@ -21,8 +21,11 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.InetSocketAddress;
+import java.net.SocketTimeoutException;
 import java.nio.ByteBuffer;
+import java.nio.channels.Channels;
 import java.nio.channels.ClosedChannelException;
+import java.nio.channels.ReadableByteChannel;
 import java.nio.channels.SelectionKey;
 import java.nio.channels.SocketChannel;
 import java.security.KeyStore;
@@ -449,6 +452,10 @@ public class Link {
         ByteBuffer out_pkgBuf = ByteBuffer.allocate(sslSession.getPacketBufferSize() + 40);
         ByteBuffer out_appBuf = ByteBuffer.allocate(sslSession.getApplicationBufferSize() + 40);
         int count;
+        ch.socket().setSoTimeout(10 * 1000);
+        InputStream inStream = ch.socket().getInputStream();
+        // Use readCh to make sure the timeout on reading is working
+        ReadableByteChannel readCh = Channels.newChannel(inStream);
 
         if (isClient) {
             hsStatus = SSLEngineResult.HandshakeStatus.NEED_WRAP;
@@ -479,7 +486,15 @@ public class Link {
                 // One packet may contained multiply operation
                 if (in_pkgBuf.position() == 0 || !in_pkgBuf.hasRemaining()) {
                     in_pkgBuf.clear();
-                    count = ch.read(in_pkgBuf);
+                    count = 0;
+                    try {
+                    	count = readCh.read(in_pkgBuf);
+                    } catch (SocketTimeoutException ex) {
+                    	if (s_logger.isTraceEnabled()) {
+                            s_logger.trace("Handshake reading time out! Cut the connection");
+                    	}
+                        count = -1;
+                    }
                     if (count == -1) {
                         throw new IOException("Connection closed with -1 on reading size.");
                     }