Return-Path: X-Original-To: apmail-hc-commits-archive@www.apache.org Delivered-To: apmail-hc-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D92F01838D for ; Wed, 17 Feb 2016 18:22:53 +0000 (UTC) Received: (qmail 31395 invoked by uid 500); 17 Feb 2016 18:22:53 -0000 Delivered-To: apmail-hc-commits-archive@hc.apache.org Received: (qmail 31351 invoked by uid 500); 17 Feb 2016 18:22:53 -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 31330 invoked by uid 99); 17 Feb 2016 18:22:53 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Feb 2016 18:22:53 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id E4699182319 for ; Wed, 17 Feb 2016 18:22:52 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.671 X-Spam-Level: X-Spam-Status: No, score=0.671 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-0.329] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id HQdFgqWbaGKz for ; Wed, 17 Feb 2016 18:22:51 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 02F1166045 for ; Wed, 17 Feb 2016 13:34:14 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id A9B82E00B0 for ; Wed, 17 Feb 2016 13:34:12 +0000 (UTC) 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 843BC3A0249 for ; Wed, 17 Feb 2016 13:34:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1730831 - /httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java Date: Wed, 17 Feb 2016 13:34:12 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20160217133412.843BC3A0249@svn01-us-west.apache.org> Author: olegk Date: Wed Feb 17 13:34:12 2016 New Revision: 1730831 URL: http://svn.apache.org/viewvc?rev=1730831&view=rev Log: Fixed race condition in request initialization code and #endOfInput method in async client protocol handlers Modified: httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java Modified: httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java?rev=1730831&r1=1730830&r2=1730831&view=diff ============================================================================== --- httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java (original) +++ httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java Wed Feb 17 13:34:12 2016 @@ -329,27 +329,30 @@ public class HttpAsyncRequestExecutor im @Override public void endOfInput(final NHttpClientConnection conn) throws IOException { final State state = getState(conn); - if (state != null) { - if (state.getRequestState().compareTo(MessageState.READY) != 0) { - state.invalidate(); - } - final HttpAsyncClientExchangeHandler handler = getHandler(conn); - if (handler != null) { - if (state.isValid()) { - handler.inputTerminated(); - } else { - handler.failed(new ConnectionClosedException("Connection closed")); + final HttpContext context = conn.getContext(); + synchronized (context) { + if (state != null) { + if (state.getRequestState().compareTo(MessageState.READY) != 0) { + state.invalidate(); + } + final HttpAsyncClientExchangeHandler handler = getHandler(conn); + if (handler != null) { + if (state.isValid()) { + handler.inputTerminated(); + } else { + handler.failed(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(); } - // 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(); } @Override @@ -396,11 +399,11 @@ public class HttpAsyncRequestExecutor im this.exceptionLogger.log(ex); } - private State getState(final NHttpConnection conn) { + private static State getState(final NHttpConnection conn) { return (State) conn.getContext().getAttribute(HTTP_EXCHANGE_STATE); } - private HttpAsyncClientExchangeHandler getHandler(final NHttpConnection conn) { + private static HttpAsyncClientExchangeHandler getHandler(final NHttpConnection conn) { return (HttpAsyncClientExchangeHandler) conn.getContext().getAttribute(HTTP_HANDLER); }