From be2dfc9a7ae8a7c09e0d4df20d713a52e1bb8e7c Mon Sep 17 00:00:00 2001
From: boli <boli@localhost>
Date: Thu, 09 Apr 2009 16:01:04 +0000
Subject: [PATCH] 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).
---
opends/src/server/org/opends/server/protocols/ldap/LDAPConnectionHandler.java | 46 +++++++++++++++++++++++++++++++---------------
1 files changed, 31 insertions(+), 15 deletions(-)
diff --git a/opends/src/server/org/opends/server/protocols/ldap/LDAPConnectionHandler.java b/opends/src/server/org/opends/server/protocols/ldap/LDAPConnectionHandler.java
index 18889b9..52bf912 100644
--- a/opends/src/server/org/opends/server/protocols/ldap/LDAPConnectionHandler.java
+++ b/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
--
Gitblit v1.10.0