From derby-commits-return-14928-apmail-db-derby-commits-archive=db.apache.org@db.apache.org Mon Oct 10 06:39:17 2011 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 742A5768A for ; Mon, 10 Oct 2011 06:39:17 +0000 (UTC) Received: (qmail 89552 invoked by uid 500); 10 Oct 2011 06:39:16 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 89491 invoked by uid 500); 10 Oct 2011 06:39:16 -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 89484 invoked by uid 99); 10 Oct 2011 06:39:14 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Oct 2011 06:39:14 +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; Mon, 10 Oct 2011 06:39:13 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 69E5323889D7; Mon, 10 Oct 2011 06:38:53 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1180790 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/services/daemon/IndexStatisticsDaemonImpl.java Date: Mon, 10 Oct 2011 06:38:53 -0000 To: derby-commits@db.apache.org From: kristwaa@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111010063853.69E5323889D7@eris.apache.org> Author: kristwaa Date: Mon Oct 10 06:38:52 2011 New Revision: 1180790 URL: http://svn.apache.org/viewvc?rev=1180790&view=rev Log: DERBY-5447: Deadlock in AutomaticIndexStatisticsTest.testShutdownWhileScanningThenDelete (BasePage.releaseExclusive and Observable.deleteObserver (BaseContainerHandle)) Clean the daemon context only after the running worker thread (if any) has finished to avoid Java deadlock when closing the container handles obtained with the context. The deadlock is intermittent, but can easily be reproduced, and involves synchronization in BasePage and in java.util.Observable. Patch file: derby-5447-2a-change_istat_shutdown.diff Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/daemon/IndexStatisticsDaemonImpl.java Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/daemon/IndexStatisticsDaemonImpl.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/daemon/IndexStatisticsDaemonImpl.java?rev=1180790&r1=1180789&r2=1180790&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/daemon/IndexStatisticsDaemonImpl.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/daemon/IndexStatisticsDaemonImpl.java Mon Oct 10 06:38:52 2011 @@ -886,9 +886,14 @@ public class IndexStatisticsDaemonImpl */ public void stop() { Thread threadToWaitFor = null; + // Controls execution of last cleanup step outside of the synchronized + // block. Should only be done once, and this is ensured by the guard on + // 'queue' and the value of 'daemonDisabled'. + boolean clearContext = false; synchronized (queue) { if (!daemonDisabled) { + clearContext = true; StringBuffer sb = new StringBuffer(100); sb.append("stopping daemon, active="). append(runningThread != null). @@ -913,12 +918,7 @@ public class IndexStatisticsDaemonImpl threadToWaitFor = runningThread; runningThread = null; queue.clear(); - // DERBY-5336: Trigger cleanup code to remove the context - // from the context service. This pattern was - // copied from BasicDaemon. - ctxMgr.cleanupOnError(StandardException.normalClose(), false); } - } // Wait for the currently running thread, if there is one. Must do @@ -935,6 +935,17 @@ public class IndexStatisticsDaemonImpl } } + + // DERBY-5447: Remove the context only after the running daemon thread + // (if any) has been shut down to avoid Java deadlocks + // when closing the container handles obtained with this + // context. + if (clearContext) { + // DERBY-5336: Trigger cleanup code to remove the context + // from the context service. This pattern was + // copied from BasicDaemon. + ctxMgr.cleanupOnError(StandardException.normalClose(), false); + } }