You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by km...@apache.org on 2011/11/17 06:08:32 UTC
svn commit: r1203050 -
/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/ClientThread.java
Author: kmarsden
Date: Thu Nov 17 05:08:32 2011
New Revision: 1203050
URL: http://svn.apache.org/viewvc?rev=1203050&view=rev
Log:
DERBY-5347 Derby loops filling logs and consuming all CPU with repeated error: java.net.SocketException: EDC5122I Input/output error.
If accept does not block and continues to throw errors, retry and log the exception two more times times at 1 second intervals and then if it still fails, shutdown the server.
Modified:
db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/ClientThread.java
Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/ClientThread.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/ClientThread.java?rev=1203050&r1=1203049&r2=1203050&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/ClientThread.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/ClientThread.java Thu Nov 17 05:08:32 2011
@@ -57,22 +57,15 @@ final class ClientThread extends Thread
try { // Check for underlying InterruptedException,
// SSLException and IOException
- try{ // Check for PrivilegedActionException
-
- clientSocket =
- (Socket) AccessController.doPrivileged(
- new PrivilegedExceptionAction() {
- public Object run() throws IOException
- {
- return serverSocket.accept();
- }
- }
- );
+ try { // Check for PrivilegedActionException
+ clientSocket =
+ acceptClientWithRetry();
// Server may have been shut down. If so, close this
// client socket and break out of the loop.
// DERBY-3869
if (parent.getShutdown()) {
- clientSocket.close();
+ if (clientSocket != null)
+ clientSocket.close();
return;
}
@@ -149,6 +142,52 @@ final class ClientThread extends Thread
} // end for(;;)
}// end run()
+
+ /**
+ * Perform a server socket accept. Allow three attempts with a one second
+ * wait between each
+ *
+ * @return client socket or null if accept failed.
+ *
+ */
+ private Socket acceptClientWithRetry() {
+ return (Socket) AccessController.doPrivileged(
+ new PrivilegedAction() {
+ public Object run() {
+ for (int trycount = 1; trycount <= 3; trycount++) {
+ try {
+ // DERBY-5347 Need to exit if
+ // accept fails with IOException
+ // Cannot just aimlessly loop
+ // writing errors
+ return serverSocket.accept();
+ } catch (IOException acceptE) {
+ // If not a normal shutdown,
+ // log and shutdown the server
+ if (!parent.getShutdown()) {
+ parent
+ .consoleExceptionPrintTrace(acceptE);
+ if (trycount == 3) {
+ // give up after three tries
+ parent.directShutdownInternal();
+ } else {
+ // otherwise wait 1 second and retry
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException ie) {
+ parent
+ .consoleExceptionPrintTrace(ie);
+ }
+ }
+ }
+ }
+ }
+ return null; // no socket to return after three tries
+ }
+ }
+
+ );
+ }
}