hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject [09/50] httpcomponents-core git commit: HTTPCORE-319: Non-blocking SSLIOSession can fail to shut down correctly when the underlying connection gets terminated abnormally by the opposite endpoint in case there is a truncated or corrupted encrypted content
Date Tue, 09 May 2017 20:03:00 GMT
HTTPCORE-319: Non-blocking SSLIOSession can fail to shut down correctly when the underlying
connection gets terminated abnormally by the opposite endpoint in case there is a truncated
or corrupted encrypted content in the input buffer and there is still data in the output buffer
that needs to be flushed out (most likely to occur with POST or PUT requests)

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/branches/4.2.x@1415878
13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/522e23f7
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/522e23f7
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/522e23f7

Branch: refs/heads/4.2.x
Commit: 522e23f73a9fdf5be6278ff67a809ce4890aea53
Parents: 3c89738
Author: Oleg Kalnichevski <olegk@apache.org>
Authored: Fri Nov 30 22:47:58 2012 +0000
Committer: Oleg Kalnichevski <olegk@apache.org>
Committed: Fri Nov 30 22:47:58 2012 +0000

----------------------------------------------------------------------
 RELEASE_NOTES.txt                               | 10 ++++++++
 .../nio/protocol/HttpAsyncRequestExecutor.java  |  7 ++++++
 .../http/nio/protocol/HttpAsyncService.java     |  7 ++++++
 .../http/nio/reactor/ssl/SSLIOSession.java      | 24 ++++++++++++++++++--
 4 files changed, 46 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/522e23f7/RELEASE_NOTES.txt
----------------------------------------------------------------------
diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt
index 7fb79d2..e52b12e 100644
--- a/RELEASE_NOTES.txt
+++ b/RELEASE_NOTES.txt
@@ -1,3 +1,13 @@
+Changes since 4.2.3
+
+* [HTTPCORE-319] Non-blocking SSLIOSession can fail to shut down correctly when the underlying
+  connection gets terminated abnormally by the opposite endpoint in case there is a truncated
or
+  corrupted encrypted content in the input buffer and there is still data in the output buffer
+  that needs to be flushed out (most likely to occur with POST or PUT requests).
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
+
+
 Release 4.2.3
 -------------------
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/522e23f7/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
b/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
index 675b5f6..a6009b5 100644
--- a/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
+++ b/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
@@ -261,6 +261,13 @@ public class HttpAsyncRequestExecutor implements NHttpClientEventHandler
{
                 closeHandler(getHandler(conn), new ConnectionClosedException("Connection
closed"));
             }
         }
+        // Closing connection in an orderly manner and
+        // waiting for output buffer to get flushed.
+        // Do not want to wait indefinitely, though, in case
+        // the opposite end is not reading
+        if (conn.getSocketTimeout() <= 0) {
+            conn.setSocketTimeout(1000);
+        }
         conn.close();
     }
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/522e23f7/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java
b/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java
index 9b602c8..f8e9fa4 100644
--- a/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java
+++ b/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java
@@ -355,6 +355,13 @@ public class HttpAsyncService implements NHttpServerEventHandler {
     }
 
     public void endOfInput(final NHttpServerConnection conn) throws IOException {
+        // Closing connection in an orderly manner and
+        // waiting for output buffer to get flushed.
+        // Do not want to wait indefinitely, though, in case
+        // the opposite end is not reading
+        if (conn.getSocketTimeout() <= 0) {
+            conn.setSocketTimeout(1000);
+        }
         conn.close();
     }
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/522e23f7/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
b/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
index 8f8dc93..1a08f5c 100644
--- a/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
+++ b/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
@@ -304,7 +304,7 @@ public class SSLIOSession implements IOSession, SessionBufferStatus, SocketAcces
             newMask = EventMask.READ_WRITE;
             break;
         case NEED_UNWRAP:
-            newMask = EventMask.READ;
+            newMask = EventMask.READ | (this.appEventMask & EventMask.WRITE);
             break;
         case NOT_HANDSHAKING:
             newMask = this.appEventMask;
@@ -354,6 +354,9 @@ public class SSLIOSession implements IOSession, SessionBufferStatus, SocketAcces
             if (result.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING) {
                 break;
             }
+            if (this.endOfStream) {
+                break;
+            }
         }
         return decrypted;
     }
@@ -563,8 +566,17 @@ public class SSLIOSession implements IOSession, SessionBufferStatus,
SocketAcces
         this.session.setAttribute(name, obj);
     }
 
+    private static void formatOps(final StringBuilder buffer, int ops) {
+        if ((ops & SelectionKey.OP_READ) > 0) {
+            buffer.append('r');
+        }
+        if ((ops & SelectionKey.OP_WRITE) > 0) {
+            buffer.append('w');
+        }
+    }
+
     @Override
-    public String toString() {
+    public synchronized String toString() {
         StringBuilder buffer = new StringBuilder();
         buffer.append(this.session);
         buffer.append("[");
@@ -580,7 +592,15 @@ public class SSLIOSession implements IOSession, SessionBufferStatus,
SocketAcces
             break;
         }
         buffer.append("][");
+        formatOps(buffer, this.appEventMask);
+        buffer.append("][");
         buffer.append(this.sslEngine.getHandshakeStatus());
+        if (this.sslEngine.isInboundDone()) {
+            buffer.append("][inbound done][");
+        }
+        if (this.sslEngine.isOutboundDone()) {
+            buffer.append("][outbound done][");
+        }
         if (this.endOfStream) {
             buffer.append("][EOF][");
         }


Mime
View raw message