You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2017/11/21 14:29:52 UTC
[2/2] httpcomponents-core git commit: Bugfix: prevent a tight loop in
non-blocking SSL I/O sessions due to a HTTP/2 frame fragment in the SSL input
buffer
Bugfix: prevent a tight loop in non-blocking SSL I/O sessions due to a HTTP/2 frame fragment in the SSL input buffer
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/1c3a5712
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/1c3a5712
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/1c3a5712
Branch: refs/heads/master
Commit: 1c3a57129cbc33f099cc717fa6e2feef48cc1caf
Parents: f541cad
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Tue Nov 21 15:20:56 2017 +0100
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Tue Nov 21 15:20:56 2017 +0100
----------------------------------------------------------------------
.../hc/core5/reactor/InternalDataChannel.java | 17 +++++++++--------
.../org/apache/hc/core5/reactor/ssl/SSLBuffer.java | 3 +++
.../apache/hc/core5/reactor/ssl/SSLIOSession.java | 17 ++++++++++++-----
3 files changed, 24 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/1c3a5712/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalDataChannel.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalDataChannel.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalDataChannel.java
index d48e961..34f3ec8 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalDataChannel.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalDataChannel.java
@@ -107,19 +107,20 @@ final class InternalDataChannel extends InternalChannel implements TlsCapableIOS
}
if ((readyOps & SelectionKey.OP_READ) != 0) {
ioSession.updateReadTime();
- if (tlsSession.isAppInputReady()) {
- do {
+ do {
+ tlsSession.resetReadCount();
+ if (tlsSession.isAppInputReady()) {
if (sessionListener != null) {
sessionListener.inputReady(this);
}
final IOEventHandler handler = getEventHandler();
handler.inputReady(this);
- } while (tlsSession.hasInputDate());
- }
- tlsSession.inboundTransport();
- if (sessionListener != null) {
- sessionListener.tlsInbound(tlsSession);
- }
+ }
+ tlsSession.inboundTransport();
+ if (sessionListener != null) {
+ sessionListener.tlsInbound(tlsSession);
+ }
+ } while (tlsSession.getReadCount() > 0);
}
if ((readyOps & SelectionKey.OP_WRITE) != 0) {
ioSession.updateWriteTime();
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/1c3a5712/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLBuffer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLBuffer.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLBuffer.java
index 9afb6a6..18176b4 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLBuffer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLBuffer.java
@@ -28,9 +28,12 @@ package org.apache.hc.core5.reactor.ssl;
import java.nio.ByteBuffer;
+import org.apache.hc.core5.annotation.Internal;
+
/**
* Managed internal SSL buffer.
*/
+@Internal
interface SSLBuffer {
/**
* Allocates the resources required for this buffer, or returns the resources already allocated for this buffer.
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/1c3a5712/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
index 6e30d97..a462197 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
@@ -34,6 +34,7 @@ import java.nio.channels.ByteChannel;
import java.nio.channels.CancelledKeyException;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.SelectionKey;
+import java.util.concurrent.atomic.AtomicLong;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
@@ -44,6 +45,7 @@ import javax.net.ssl.SSLException;
import javax.net.ssl.SSLSession;
import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.Internal;
import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.function.Callback;
import org.apache.hc.core5.io.ShutdownType;
@@ -64,6 +66,7 @@ import org.apache.hc.core5.util.Asserts;
* @since 4.2
*/
@Contract(threading = ThreadingBehavior.SAFE_CONDITIONAL)
+@Internal
public class SSLIOSession implements IOSession {
private static final ByteBuffer EMPTY_BUFFER = ByteBuffer.allocate(0);
@@ -78,6 +81,7 @@ public class SSLIOSession implements IOSession {
private final SSLSessionInitializer initializer;
private final SSLSessionVerifier verifier;
private final Callback<SSLIOSession> callback;
+ private final AtomicLong bytesReadCount;
private int appEventMask;
@@ -181,6 +185,7 @@ public class SSLIOSession implements IOSession {
}
};
+ this.bytesReadCount = new AtomicLong(0);
}
@Override
@@ -584,6 +589,7 @@ public class SSLIOSession implements IOSession {
if (inPlainBuf.position() == 0) {
this.inPlain.release();
}
+ bytesReadCount.addAndGet(n);
return n;
}
if (this.endOfStream) {
@@ -592,11 +598,12 @@ public class SSLIOSession implements IOSession {
return 0;
}
- /**
- * @since 5.0
- */
- public synchronized boolean hasInputDate() {
- return this.inPlain.hasData();
+ public void resetReadCount() {
+ bytesReadCount.set(0L);
+ }
+
+ public long getReadCount() {
+ return bytesReadCount.get();
}
@Override