Return-Path: X-Original-To: apmail-hc-dev-archive@www.apache.org Delivered-To: apmail-hc-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 271059AC6 for ; Wed, 11 Apr 2012 08:32:59 +0000 (UTC) Received: (qmail 75669 invoked by uid 500); 11 Apr 2012 08:32:58 -0000 Delivered-To: apmail-hc-dev-archive@hc.apache.org Received: (qmail 75568 invoked by uid 500); 11 Apr 2012 08:32:58 -0000 Mailing-List: contact dev-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 dev@hc.apache.org Received: (qmail 75533 invoked by uid 99); 11 Apr 2012 08:32:57 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Apr 2012 08:32:57 +0000 X-ASF-Spam-Status: No, hits=1.8 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT,HTML_MESSAGE,NORMAL_HTTP_TO_IP,RCVD_IN_DNSWL_LOW,SPF_PASS,T_FRT_STOCK2,WEIRD_PORT X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of hiranya911@gmail.com designates 209.85.212.51 as permitted sender) Received: from [209.85.212.51] (HELO mail-vb0-f51.google.com) (209.85.212.51) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Apr 2012 08:32:52 +0000 Received: by vbip1 with SMTP id p1so443774vbi.10 for ; Wed, 11 Apr 2012 01:32:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=8GPicMWZBPNcJIUXliVZvR1CLUS7rwhaMdkChFQAetI=; b=AxscJXiR+7mbc+6OJ9CY/icut0M8DqP3EGxx0L0Rv5xIYZ3HcnuBoFFmxPwHUatZcx GJ/PLMOkjoqkw7b/cSPtGFEMTbzHJy6zVDvm0UUFZ3PvX4bDRTB0+/+i7+EfIZiImafs JIBV6CxKfPpdvqxb8grtKFM+zAz7N/9GYWXDz9Yf7RTjEBgRRnjjGkFwT14ny/20EN7R SnrpV7OEDzrKM7Y8nrsHbo4i2uH4iEkXv94omTvZv/vCUzzO4MvdfIP2acF9FMPLKQJf YPpsk3UGRtxQ/zgtS+5YJUfG6D7mKN7d+lbrBc8oIKlfbyPHTzn1Nh1+/qgZPMHrhGww JJjw== MIME-Version: 1.0 Received: by 10.52.33.67 with SMTP id p3mr5908931vdi.18.1334133152015; Wed, 11 Apr 2012 01:32:32 -0700 (PDT) Received: by 10.220.75.11 with HTTP; Wed, 11 Apr 2012 01:32:31 -0700 (PDT) In-Reply-To: References: Date: Wed, 11 Apr 2012 14:02:31 +0530 Message-ID: Subject: Re: Possible Race Condition Due to NHTTP Connection Pooling From: Hiranya Jayathilaka To: HttpComponents Project , dev@synapse.apache.org Content-Type: multipart/alternative; boundary=20cf3079bff89be55604bd631464 X-Virus-Checked: Checked by ClamAV on apache.org --20cf3079bff89be55604bd631464 Content-Type: text/plain; charset=ISO-8859-1 It looks like calling setSocketTimeout on the NHttpClientConnection would reset the last access time attribute of the underlying IOSession. So if we do the following before the connection is returned from the pool, will that work? conn.setSocketTimeout(conn.getSocketTimeout()); Thanks, Hiranya On Wed, Apr 11, 2012 at 1:36 PM, Hiranya Jayathilaka wrote: > Hi Devs, > > I have identified a possible race condition in the Synapse NHTTP > transport. This happens because Synapse pools NHttpClientConnection > instances for easy reuse. Imagine the following scenario: > > 1. Synapse receives a message which should be forwarded to X > 2. Synapse detects that a previously established connection to X already > exists in the NHTTP connection pool > 3. Synapse attempts to forward the message over the above connection > > Now if the connection has stayed in the connection pool for a fairly long > time in idle state, then the ClientHandler#timeout event may get fired on > it as Synapse attempts to send the new request over it. In this case the > Synapse ClientHandler simply closes the connection which causes the request > invocation to fail. I'm able to reproduce this issue consistently with a > simple mutation test: > > [2012-04-11 13:10:34,927] DEBUG - ConnectionPool A connection to host : > localhost on port : 9000 is available in the pool, and will be reused > [2012-04-11 13:10:34,929] DEBUG - ClientHandler Connection timeout For : > 127.0.0.1:9000 > [2012-04-11 13:10:34,930] DEBUG - headers >> POST > /services/SimpleStockQuoteService HTTP/1.1 > [2012-04-11 13:10:34,931] DEBUG - headers >> Content-Type: text/xml; > charset=UTF-8 > [2012-04-11 13:10:34,931] DEBUG - headers >> SOAPAction: "urn:getQuote" > [2012-04-11 13:10:34,931] DEBUG - headers >> Transfer-Encoding: chunked > [2012-04-11 13:10:34,931] DEBUG - headers >> Host: localhost:9000 > [2012-04-11 13:10:34,931] DEBUG - headers >> Connection: Keep-Alive > [2012-04-11 13:10:34,932] DEBUG - headers >> User-Agent: > Synapse-HttpComponents-NIO > [2012-04-11 13:10:34,932] DEBUG - ClientHandler Connection to remote > address : localhost/127.0.0.1:9000 from local address : /127.0.0.1:35208is closed! > [2012-04-11 13:10:34,933] DEBUG - HttpCoreNIOSender An existing connection > reused to : localhost:9000 > [2012-04-11 13:10:34,933] DEBUG - ClientHandler HTTP connection > 127.0.0.1:35208->127.0.0.1:9000: Closed > [2012-04-11 13:10:34,933] DEBUG - Axis2HttpRequest Start streaming > outgoing http request : [Message ID : > urn:uuid:ec5957cc-73a6-4877-b76f-a26b72b2edd3] > [2012-04-11 13:10:34,934] DEBUG - ClientHandler Keep-alive connection > closed For : 127.0.0.1:9000 For Request : Axis2Request [Message ID : > urn:uuid:ec5957cc-73a6-4877-b76f-a26b72b2edd3] [Status Completed : true] > [Status SendingCompleted : false] > [2012-04-11 13:10:34,934] DEBUG - ClientHandler Connection to remote > address : localhost/127.0.0.1:9000 from local address : /127.0.0.1:35208is closed! > [2012-04-11 13:10:34,952] DEBUG - ClientHandler Sending Fault for Request > with Message ID : urn:uuid:ec5957cc-73a6-4877-b76f-a26b72b2edd3 > > > I believe that ideally we should "reset the clock" for connections > returned from the ConnectionPool. That way they would behave as newly > established connections regardless of how much time they have spent in the > connection pool. Is there a way to achieve this? > > Thanks > -- > Hiranya Jayathilaka > Associate Technical Lead; > WSO2 Inc.; http://wso2.org > E-mail: hiranya@wso2.com; Mobile: +94 77 633 3491 > Blog: http://techfeast-hiranya.blogspot.com > -- Hiranya Jayathilaka Associate Technical Lead; WSO2 Inc.; http://wso2.org E-mail: hiranya@wso2.com; Mobile: +94 77 633 3491 Blog: http://techfeast-hiranya.blogspot.com --20cf3079bff89be55604bd631464--