Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id E8D79200CA7 for ; Tue, 9 May 2017 22:03:32 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id E76BB160BCE; Tue, 9 May 2017 20:03:32 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 16398160BCD for ; Tue, 9 May 2017 22:03:31 +0200 (CEST) Received: (qmail 88492 invoked by uid 500); 9 May 2017 20:03:31 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 88224 invoked by uid 99); 9 May 2017 20:03:31 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 May 2017 20:03:31 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id F40C1EE68D; Tue, 9 May 2017 20:03:30 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: olegk@apache.org To: commits@hc.apache.org Date: Tue, 09 May 2017 20:03:36 -0000 Message-Id: <5e2a68a282284535ba2bd890af99b42e@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [07/35] httpcomponents-core git commit: HTTPCORE-260: Non-blocking SSL I/O session can terminate prematurely causing message body truncation when message content is chunk coded and the connection is closed on the opposite end archived-at: Tue, 09 May 2017 20:03:33 -0000 HTTPCORE-260: Non-blocking SSL I/O session can terminate prematurely causing message body truncation when message content is chunk coded and the connection is closed on the opposite end git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/branches/4.1.x@1134570 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/ee0f3777 Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/ee0f3777 Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/ee0f3777 Branch: refs/heads/4.1.x Commit: ee0f37775b84b93ad8d1191f30c7299376891d70 Parents: 7b3c167 Author: Oleg Kalnichevski Authored: Sat Jun 11 11:15:25 2011 +0000 Committer: Oleg Kalnichevski Committed: Sat Jun 11 11:15:25 2011 +0000 ---------------------------------------------------------------------- RELEASE_NOTES.txt | 11 +++++ .../http/impl/nio/reactor/IOSessionImpl.java | 19 ++++--- .../http/impl/nio/reactor/SSLIOSession.java | 52 ++++++++++---------- 3 files changed, 51 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ee0f3777/RELEASE_NOTES.txt ---------------------------------------------------------------------- diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index 7934625..2c731d7 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -1,3 +1,14 @@ +Changes since 4.1.1 +------------------- + +* [HTTPCORE-260] Non-blocking SSL I/O session can terminate prematurely causing message body + truncation when message content is chunk coded and the connection is closed on the opposite end. + Contributed by Oleg Kalnichevski + +* [HTTPCORE-257] Fixed incorrect results produced by DefaultConnectionReuseStrategy when handling + response messages whose content entity has been decoded or modified by a protocol interceptor. + Contributed by Oleg Kalnichevski + Release 4.1.1 ------------------- http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ee0f3777/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java ---------------------------------------------------------------------- diff --git a/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java b/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java index 80a986a..97f0821 100644 --- a/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java +++ b/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java @@ -251,7 +251,6 @@ public class IOSessionImpl implements IOSession { } private static void formatOps(final StringBuffer buffer, int ops) { - buffer.append('['); if ((ops & SelectionKey.OP_READ) > 0) { buffer.append('r'); } @@ -264,21 +263,29 @@ public class IOSessionImpl implements IOSession { if ((ops & SelectionKey.OP_CONNECT) > 0) { buffer.append('c'); } - buffer.append(']'); } @Override public synchronized String toString() { StringBuffer buffer = new StringBuffer(); buffer.append("["); + switch (this.status) { + case ACTIVE: + buffer.append("ACTIVE"); + break; + case CLOSING: + buffer.append("CLOSING"); + break; + case CLOSED: + buffer.append("CLOSED"); + break; + } + buffer.append("]["); if (this.key.isValid()) { - buffer.append("interest ops: "); formatOps(buffer, this.interestOpsCallback != null ? this.currentEventMask : this.key.interestOps()); - buffer.append("; ready ops: "); + buffer.append(":"); formatOps(buffer, this.key.readyOps()); - } else { - buffer.append("invalid"); } buffer.append("]"); return buffer.toString(); http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ee0f3777/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSession.java ---------------------------------------------------------------------- diff --git a/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSession.java b/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSession.java index bfed421..5e67cc2 100644 --- a/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSession.java +++ b/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSession.java @@ -156,9 +156,6 @@ public class SSLIOSession implements IOSession, SessionBufferStatus { if (result.getStatus() != Status.OK) { handshaking = false; } - if (result.getStatus() == Status.CLOSED) { - this.status = CLOSED; - } break; case NEED_UNWRAP: // Process incoming handshake data @@ -168,12 +165,6 @@ public class SSLIOSession implements IOSession, SessionBufferStatus { if (result.getStatus() != Status.OK) { handshaking = false; } - if (result.getStatus() == Status.CLOSED) { - this.status = CLOSED; - } - if (result.getStatus() == Status.BUFFER_UNDERFLOW && this.endOfStream) { - this.status = CLOSED; - } break; case NEED_TASK: Runnable r = this.sslEngine.getDelegatedTask(); @@ -198,7 +189,8 @@ public class SSLIOSession implements IOSession, SessionBufferStatus { } private void updateEventMask() { - if (this.sslEngine.isInboundDone() && this.sslEngine.isOutboundDone()) { + if (this.status == CLOSING && + this.sslEngine.isInboundDone() && this.sslEngine.isOutboundDone()) { this.status = CLOSED; } if (this.status == CLOSED) { @@ -255,12 +247,6 @@ public class SSLIOSession implements IOSession, SessionBufferStatus { this.inEncrypted.compact(); opStatus = result.getStatus(); - if (opStatus == Status.CLOSED) { - this.status = CLOSED; - } - if (opStatus == Status.BUFFER_UNDERFLOW && this.endOfStream) { - this.status = CLOSED; - } if (opStatus == Status.OK) { decrypted = true; } @@ -351,18 +337,19 @@ public class SSLIOSession implements IOSession, SessionBufferStatus { } } - public void close() { - if (this.status != ACTIVE) { + public synchronized void close() { + if (this.status >= CLOSING) { return; } this.status = CLOSING; - synchronized(this) { - this.sslEngine.closeOutbound(); - updateEventMask(); - } + this.sslEngine.closeOutbound(); + updateEventMask(); } - public void shutdown() { + public synchronized void shutdown() { + if (this.status == CLOSED) { + return; + } this.status = CLOSED; this.session.shutdown(); } @@ -372,7 +359,7 @@ public class SSLIOSession implements IOSession, SessionBufferStatus { } public boolean isClosed() { - return this.status != ACTIVE; + return this.status >= CLOSING; } public synchronized boolean isInboundDone() { @@ -454,8 +441,23 @@ public class SSLIOSession implements IOSession, SessionBufferStatus { public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append(this.session); - buffer.append("[SSL handshake status: "); + buffer.append("["); + switch (this.status) { + case ACTIVE: + buffer.append("ACTIVE"); + break; + case CLOSING: + buffer.append("CLOSING"); + break; + case CLOSED: + buffer.append("CLOSED"); + break; + } + buffer.append("]["); buffer.append(this.sslEngine.getHandshakeStatus()); + if (this.endOfStream) { + buffer.append("EOF]["); + } buffer.append("]["); buffer.append(this.inEncrypted.position()); buffer.append("][");