You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ya...@apache.org on 2014/01/02 22:56:06 UTC
git commit: updated refs/heads/4.2 to 358a7d0
Updated Branches:
refs/heads/4.2 7234af625 -> 358a7d06f
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/358a7d06
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/358a7d06
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/358a7d06
Branch: refs/heads/4.2
Commit: 358a7d06f2514f093796c6917f1bfbf245a7b9ae
Parents: 7234af6
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:55:41 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/358a7d06/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.");
}