hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1415878 - in /httpcomponents/httpcore/branches/4.2.x: ./ httpcore-nio/src/main/java/org/apache/http/nio/protocol/ httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/
Date Fri, 30 Nov 2012 22:47:58 GMT
Author: olegk
Date: Fri Nov 30 22:47:58 2012
New Revision: 1415878

URL: http://svn.apache.org/viewvc?rev=1415878&view=rev
Log:
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)

Modified:
    httpcomponents/httpcore/branches/4.2.x/RELEASE_NOTES.txt
    httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
    httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java
    httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java

Modified: httpcomponents/httpcore/branches/4.2.x/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.2.x/RELEASE_NOTES.txt?rev=1415878&r1=1415877&r2=1415878&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.2.x/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpcore/branches/4.2.x/RELEASE_NOTES.txt Fri Nov 30 22:47:58 2012
@@ -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
 -------------------
 

Modified: httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java?rev=1415878&r1=1415877&r2=1415878&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
(original)
+++ httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
Fri Nov 30 22:47:58 2012
@@ -261,6 +261,13 @@ public class HttpAsyncRequestExecutor im
                 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();
     }
 

Modified: httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java?rev=1415878&r1=1415877&r2=1415878&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java
(original)
+++ httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java
Fri Nov 30 22:47:58 2012
@@ -355,6 +355,13 @@ public class HttpAsyncService implements
     }
 
     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();
     }
 

Modified: httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java?rev=1415878&r1=1415877&r2=1415878&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
(original)
+++ httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
Fri Nov 30 22:47:58 2012
@@ -304,7 +304,7 @@ public class SSLIOSession implements IOS
             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 IOS
             if (result.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING) {
                 break;
             }
+            if (this.endOfStream) {
+                break;
+            }
         }
         return decrypted;
     }
@@ -563,8 +566,17 @@ public class SSLIOSession implements IOS
         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 IOS
             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