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




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<String, Object>());
         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
      * <code>0</code> signifies the session cannot time out.
      *

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to