mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

boli
09.01.2009 be2dfc9a7ae8a7c09e0d4df20d713a52e1bb8e7c
Fix for 3913: Ignore SocketExceptions when setting TCP properties on new connections. This can be caused on Solaris by a connection that is immediately closed after it is opened (TCP ping).
1 files modified
46 ■■■■■ changed files
opends/src/server/org/opends/server/protocols/ldap/LDAPConnectionHandler.java 46 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/protocols/ldap/LDAPConnectionHandler.java
@@ -41,6 +41,7 @@
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketException;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
@@ -904,7 +905,15 @@
              SelectionKey key = iterator.next();
              iterator.remove();
              if (key.isAcceptable()) {
                acceptConnection(key);
                // Accept the new client connection.
                ServerSocketChannel serverChannel = (ServerSocketChannel) key
                    .channel();
                SocketChannel clientChannel = serverChannel
                    .accept();
                if(clientChannel != null)
                {
                  acceptConnection(clientChannel);
                }
              }
              if(selectorState == 0 && enabled && (!shutdownRequested) &&
@@ -994,18 +1003,29 @@
    }
  }
  private void acceptConnection(SelectionKey key)
      throws IOException, DirectoryException
  private void acceptConnection(SocketChannel clientChannel)
      throws DirectoryException
  {
    // Accept the new client connection.
    ServerSocketChannel serverChannel = (ServerSocketChannel) key
        .channel();
    SocketChannel clientChannel = serverChannel
        .accept();
    if(clientChannel == null)
    try
    {
      // There wasn't a connection pending.
      clientChannel.socket().setKeepAlive(
          currentConfig.isUseTCPKeepAlive());
      clientChannel.socket().setTcpNoDelay(
          currentConfig.isUseTCPNoDelay());
    }
    catch(SocketException se)
    {
      // TCP error occured because conneciton reset/closed? In any case,
      // just close it and ignore.
      // See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6378870
      try
      {
        clientChannel.close();
      }
      catch(Exception e)
      {
        // Ignore any exceptions while closing the channel.
      }
      return;
    }
@@ -1050,10 +1070,6 @@
              clientConnection.getServerHostPort()));
      return;
    }
    clientChannel.socket().setKeepAlive(
        currentConfig.isUseTCPKeepAlive());
    clientChannel.socket().setTcpNoDelay(
        currentConfig.isUseTCPNoDelay());
    // If we've gotten here, then we'll take the
    // connection so invoke the post-connect plugins and