Fix for too early disconnects on slow client connections. (#563)
authorcli
Fri, 25 Dec 2009 15:42:46 +0100
changeset 25dd05c3f2fa24
parent 24 2ff819fa5be1
child 26 407c428adb5b
Fix for too early disconnects on slow client connections. (#563)
org/sonews/daemon/ChannelLineBuffers.java
org/sonews/daemon/ChannelWriter.java
org/sonews/daemon/Connections.java
org/sonews/daemon/NNTPConnection.java
org/sonews/storage/impl/JDBCDatabase.java
     1.1 --- a/org/sonews/daemon/ChannelLineBuffers.java	Wed Aug 26 17:04:04 2009 +0200
     1.2 +++ b/org/sonews/daemon/ChannelLineBuffers.java	Fri Dec 25 15:42:46 2009 +0100
     1.3 @@ -124,6 +124,18 @@
     1.4        }
     1.5      }
     1.6    }
     1.7 +
     1.8 +  /**
     1.9 +   * @return false if there are output buffers pending to be written to the
    1.10 +   * client.
    1.11 +   */
    1.12 +  boolean isOutputBufferEmpty()
    1.13 +  {
    1.14 +    synchronized(outputBuffers)
    1.15 +    {
    1.16 +      return outputBuffers.isEmpty();
    1.17 +    }
    1.18 +  }
    1.19    
    1.20    /**
    1.21     * Goes through the input buffer of the given channel and searches
     2.1 --- a/org/sonews/daemon/ChannelWriter.java	Wed Aug 26 17:04:04 2009 +0200
     2.2 +++ b/org/sonews/daemon/ChannelWriter.java	Fri Dec 25 15:42:46 2009 +0100
     2.3 @@ -169,6 +169,9 @@
     2.4            // events until we have something to write to the socket channel
     2.5            //selKey.cancel();
     2.6            selKey.interestOps(0);
     2.7 +          // Update activity timestamp to prevent too early disconnects
     2.8 +          // on slow client connections
     2.9 +          connection.setLastActivity(System.currentTimeMillis());
    2.10            return;
    2.11          }
    2.12   
     3.1 --- a/org/sonews/daemon/Connections.java	Wed Aug 26 17:04:04 2009 +0200
     3.2 +++ b/org/sonews/daemon/Connections.java	Fri Dec 25 15:42:46 2009 +0100
     3.3 @@ -134,7 +134,8 @@
     3.4          while (iter.hasNext())
     3.5          {
     3.6            conn = iter.next();
     3.7 -          if((System.currentTimeMillis() - conn.getLastActivity()) > timeoutMillis)
     3.8 +          if((System.currentTimeMillis() - conn.getLastActivity()) > timeoutMillis
     3.9 +              && conn.getBuffers().isOutputBufferEmpty())
    3.10            {
    3.11              // A connection timeout has occurred so purge the connection
    3.12              iter.remove();
     4.1 --- a/org/sonews/daemon/NNTPConnection.java	Wed Aug 26 17:04:04 2009 +0200
     4.2 +++ b/org/sonews/daemon/NNTPConnection.java	Fri Dec 25 15:42:46 2009 +0100
     4.3 @@ -18,7 +18,6 @@
     4.4  
     4.5  package org.sonews.daemon;
     4.6  
     4.7 -import org.sonews.util.Log;
     4.8  import java.io.IOException;
     4.9  import java.net.InetSocketAddress;
    4.10  import java.net.SocketException;
    4.11 @@ -34,6 +33,7 @@
    4.12  import org.sonews.daemon.command.Command;
    4.13  import org.sonews.storage.Article;
    4.14  import org.sonews.storage.Channel;
    4.15 +import org.sonews.util.Log;
    4.16  import org.sonews.util.Stats;
    4.17  
    4.18  /**
    4.19 @@ -408,5 +408,10 @@
    4.20    {
    4.21      this.charset = charset;
    4.22    }
    4.23 +
    4.24 +  void setLastActivity(long timestamp)
    4.25 +  {
    4.26 +    this.lastActivity = timestamp;
    4.27 +  }
    4.28    
    4.29  }
     5.1 --- a/org/sonews/storage/impl/JDBCDatabase.java	Wed Aug 26 17:04:04 2009 +0200
     5.2 +++ b/org/sonews/storage/impl/JDBCDatabase.java	Fri Dec 25 15:42:46 2009 +0100
     5.3 @@ -1752,6 +1752,7 @@
     5.4      // INSERT INTO headers ...
     5.5  
     5.6      // SELECT * FROM postings WHERE article_id = ? AND group_id = ?
     5.7 +    return false;
     5.8    }
     5.9  
    5.10    /**