Return-Path: X-Original-To: apmail-db-derby-commits-archive@www.apache.org Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 93FF29B50 for ; Sat, 3 Dec 2011 00:54:23 +0000 (UTC) Received: (qmail 13519 invoked by uid 500); 3 Dec 2011 00:54:22 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 13494 invoked by uid 500); 3 Dec 2011 00:54:22 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 13483 invoked by uid 99); 3 Dec 2011 00:54:22 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 03 Dec 2011 00:54:22 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 03 Dec 2011 00:54:21 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 701232388860; Sat, 3 Dec 2011 00:54:00 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1209809 - /db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/ClientThread.java Date: Sat, 03 Dec 2011 00:54:00 -0000 To: derby-commits@db.apache.org From: kmarsden@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111203005400.701232388860@eris.apache.org> Author: kmarsden Date: Sat Dec 3 00:54:00 2011 New Revision: 1209809 URL: http://svn.apache.org/viewvc?rev=1209809&view=rev Log: DERBY-5347 Derby loops filling logs and consuming all CPU with repeated error: java.net.SocketException: EDC5122I Input/output error. Modified: db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/ClientThread.java Modified: db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/ClientThread.java URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/ClientThread.java?rev=1209809&r1=1209808&r2=1209809&view=diff ============================================================================== --- db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/ClientThread.java (original) +++ db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/ClientThread.java Sat Dec 3 00:54:00 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 + } + } + + ); + } }