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 9F9F8200BDF for ; Sun, 18 Dec 2016 13:56:39 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 9E3E5160B30; Sun, 18 Dec 2016 12:56:39 +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 E6989160B12 for ; Sun, 18 Dec 2016 13:56:38 +0100 (CET) Received: (qmail 83135 invoked by uid 500); 18 Dec 2016 12:56:38 -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 83126 invoked by uid 99); 18 Dec 2016 12:56:38 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 18 Dec 2016 12:56:38 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 985F73A0216 for ; Sun, 18 Dec 2016 12:56:37 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1774884 - /httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java Date: Sun, 18 Dec 2016 12:56:37 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20161218125637.985F73A0216@svn01-us-west.apache.org> archived-at: Sun, 18 Dec 2016 12:56:39 -0000 Author: olegk Date: Sun Dec 18 12:56:37 2016 New Revision: 1774884 URL: http://svn.apache.org/viewvc?rev=1774884&view=rev Log: Fixed infinite loop in HTTP/1.1 stream duplexer caused by a incomplete message fragment stuck in the session input buffer Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java?rev=1774884&r1=1774883&r2=1774884&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java (original) +++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java Sun Dec 18 12:56:37 2016 @@ -203,7 +203,9 @@ abstract class AbstractHttp1StreamDuplex } public final void onInput() throws HttpException, IOException { - do { + while (connState.compareTo(ConnectionState.SHUTDOWN) < 0) { + int totalBytesRead = 0; + int messagesReceived = 0; if (incomingMessage == null) { if (connState.compareTo(ConnectionState.GRACEFUL_SHUTDOWN) >= 0 && inputIdle()) { @@ -215,10 +217,12 @@ abstract class AbstractHttp1StreamDuplex do { bytesRead = inbuf.fill(ioSession.channel()); if (bytesRead > 0) { + totalBytesRead += bytesRead; inTransportMetrics.incrementBytesTransferred(bytesRead); } final IncomingMessage messageHead = incomingMessageParser.parse(inbuf, bytesRead == -1); if (messageHead != null) { + messagesReceived++; incomingMessageParser.reset(); this.version = messageHead.getVersion(); @@ -249,16 +253,19 @@ abstract class AbstractHttp1StreamDuplex if (incomingMessage != null) { final ContentDecoder contentDecoder = incomingMessage.getBody(); final int bytesRead = consumeData(contentDecoder); + if (bytesRead > 0) { + totalBytesRead += bytesRead; + } if (contentDecoder.isCompleted()) { incomingMessage = null; inputEnd(); ioSession.setEvent(SelectionKey.OP_READ); } - if (bytesRead == 0) { - break; - } } - } while (connState.compareTo(ConnectionState.SHUTDOWN) < 0 && inbuf.hasData()); + if (totalBytesRead == 0 && messagesReceived == 0) { + break; + } + } } public final void onOutput() throws IOException, HttpException {