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 AA24B69A4 for ; Sun, 26 Jun 2011 07:53:29 +0000 (UTC) Received: (qmail 60571 invoked by uid 500); 26 Jun 2011 07:53:28 -0000 Delivered-To: apmail-hc-dev-archive@hc.apache.org Received: (qmail 60380 invoked by uid 500); 26 Jun 2011 07:53:11 -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 60366 invoked by uid 99); 26 Jun 2011 07:53:04 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 26 Jun 2011 07:53:04 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,SPF_PASS,T_FRT_STOCK2 X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of asankha.apache@gmail.com designates 74.125.83.179 as permitted sender) Received: from [74.125.83.179] (HELO mail-pv0-f179.google.com) (74.125.83.179) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 26 Jun 2011 07:52:58 +0000 Received: by pvg18 with SMTP id 18so2432552pvg.10 for ; Sun, 26 Jun 2011 00:52:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:sender:message-id:date:from:user-agent :mime-version:to:subject:content-type; bh=60KJBdPJ2bBYBjl/ltCfa6D2deafrwx3e0G4yz9GF8k=; b=F2+U+cNIhpvObpmb0orFfur35HX+aLLH7u7Tj8u7QVWuhLRiFcp5QC7Qosb7J+OrVS m2Jv3nYUEktPzt32+SeodBA5Nfhe2wKTMdn/vsFiMHZFG7qnly1HLFEhkEKwdXYWZluj 9UyKzMXb/yCNg5hSCqbag9zgBw/ihag1xRoy8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:message-id:date:from:user-agent:mime-version:to:subject :content-type; b=Ui+bd+2mp4N/SxJBxUpf0Qnf2ZpInVTn7B8LQg36uT88tEhP9deKZw4rdGSrZlQyvN 3/c97P/VG6yHU+yWR8QKYV62H9MfSEs6icpe7BTImRT1rxtjzc1pFFfF4uFgkCRju5A8 Dv/jBUkU+DAxT6YSxfpP59c2aZDtan3YVZggw= Received: by 10.68.42.227 with SMTP id r3mr2515768pbl.411.1309074757634; Sun, 26 Jun 2011 00:52:37 -0700 (PDT) Received: from [192.168.1.3] ([112.135.147.172]) by mx.google.com with ESMTPS id i9sm3395605pbk.68.2011.06.26.00.52.34 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 26 Jun 2011 00:52:35 -0700 (PDT) Sender: Asankha Perera Message-ID: <4E06E540.5060506@apache.org> Date: Sun, 26 Jun 2011 13:22:32 +0530 From: "Asankha C. Perera" User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7 MIME-Version: 1.0 To: HttpComponents Project Subject: Keeping track of Socket Timeout set time Content-Type: multipart/mixed; boundary="------------090707030708060309070905" --------------090707030708060309070905 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi All I've come across this following case: 1. We establish an outgoing connection and set the socket timeout to 5 seconds (Time = t0 ) 2. After receiving the response, we want to keep the socket open for reuse for 30 seconds, and we update the timeout (Time = t1) 3. After 6 seconds since #2 above, we get an opportunity to reuse this connection, and again we set the socket timeout to 5 seconds 4. Almost immediately, the BaseIOReactor timeout check most definitely notices that the time the socket was last used (t1) is over 5 seconds from the current time, and times out the socket I've made a patch to overcome this, but would like to hear if there are any comments on it before applying.. thanks asankha PS: I've also been writing a ChunkDecoder capable of being a FileContentDecoder.. and want to submit it for review. Oleg, do you have any plans of making the 4.1.2 release soon? -- Asankha C. Perera AdroitLogic, http://adroitlogic.org http://esbmagic.blogspot.com --------------090707030708060309070905 Content-Type: text/x-patch; name="keeping-track-of-socket-timeout-setting.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="keeping-track-of-socket-timeout-setting.patch" Index: httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/BaseIOReactor.java =================================================================== --- httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/BaseIOReactor.java (revision 1139724) +++ httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/BaseIOReactor.java (working copy) @@ -257,7 +257,7 @@ SessionHandle handle = (SessionHandle) key.attachment(); IOSession session = handle.getSession(); int timeout = session.getSocketTimeout(); - if (timeout > 0) { + if (timeout > 0 && handle.getLastAccessTime() > session.getLastSocketTimeoutSetTime()) { if (handle.getLastAccessTime() + timeout < now) { try { this.eventDispatch.timeout(session); Index: httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSession.java =================================================================== --- httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSession.java (revision 1139724) +++ httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSession.java (working copy) @@ -413,6 +413,10 @@ return this.session.getSocketTimeout(); } + public long getLastSocketTimeoutSetTime() { + return this.session.getLastSocketTimeoutSetTime(); + } + public void setSocketTimeout(int timeout) { this.session.setSocketTimeout(timeout); } Index: httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java =================================================================== --- httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java (revision 1139724) +++ httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java (working copy) @@ -57,6 +57,7 @@ private volatile int currentEventMask; private volatile SessionBufferStatus bufferStatus; private volatile int socketTimeout; + private volatile long lastSocketTimeoutSetTime; /** * Creates new instance of IOSessionImpl. @@ -82,6 +83,7 @@ this.attributes = Collections.synchronizedMap(new HashMap()); this.currentEventMask = 0; this.socketTimeout = 0; + this.lastSocketTimeoutSetTime = System.currentTimeMillis(); this.status = ACTIVE; } @@ -188,8 +190,13 @@ public void setSocketTimeout(int timeout) { this.socketTimeout = timeout; + this.lastSocketTimeoutSetTime = System.currentTimeMillis(); } + public long getLastSocketTimeoutSetTime() { + return lastSocketTimeoutSetTime; + } + public synchronized void close() { if (this.status == CLOSED) { return; Index: httpcore-nio/src/main/java/org/apache/http/nio/reactor/IOSession.java =================================================================== --- httpcore-nio/src/main/java/org/apache/http/nio/reactor/IOSession.java (revision 1139724) +++ httpcore-nio/src/main/java/org/apache/http/nio/reactor/IOSession.java (working copy) @@ -152,6 +152,12 @@ int getSocketTimeout(); /** + * Returns the last time the socket timeout value was set on this session + * @return the time in ms when the socket timeout was last set + */ + public long getLastSocketTimeoutSetTime(); + + /** * Sets value of the socket timeout in milliseconds. The value of * 0 signifies the session cannot time out. * --------------090707030708060309070905 Content-Type: text/plain; charset=us-ascii --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org For additional commands, e-mail: dev-help@hc.apache.org --------------090707030708060309070905--