cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yas...@apache.org
Subject git commit: updated refs/heads/4.3 to 939f205
Date Thu, 02 Jan 2014 21:53:52 GMT
Updated Branches:
  refs/heads/4.3 61d48154f -> 939f20559


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/939f2055
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/939f2055
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/939f2055

Branch: refs/heads/4.3
Commit: 939f20559e8e6466e3c736a588e645692b3468db
Parents: 61d4815
Author: Sheng Yang <sheng.yang@citrix.com>
Authored: Thu Jan 2 11:33:46 2014 -0800
Committer: Sheng Yang <sheng.yang@citrix.com>
Committed: Thu Jan 2 13:53:42 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/939f2055/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 4b041f5..dbe31b3 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;
@@ -457,6 +460,10 @@ public class Link {
         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;
@@ -487,7 +494,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.");
                     }


Mime
View raw message