Return-Path: Delivered-To: apmail-ant-notifications-archive@locus.apache.org Received: (qmail 81513 invoked from network); 12 Jun 2008 18:29:45 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 12 Jun 2008 18:29:45 -0000 Received: (qmail 62183 invoked by uid 500); 12 Jun 2008 18:29:47 -0000 Delivered-To: apmail-ant-notifications-archive@ant.apache.org Received: (qmail 62138 invoked by uid 500); 12 Jun 2008 18:29:47 -0000 Mailing-List: contact notifications-help@ant.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ant.apache.org Delivered-To: mailing list notifications@ant.apache.org Received: (qmail 62129 invoked by uid 99); 12 Jun 2008 18:29:47 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Jun 2008 11:29:47 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Jun 2008 18:29:06 +0000 Received: by brutus.apache.org (Postfix, from userid 33) id 6DDE9234C138; Thu, 12 Jun 2008 11:28:53 -0700 (PDT) From: bugzilla@apache.org To: notifications@ant.apache.org Subject: DO NOT REPLY [Bug 45194] New: deadlock with parallel task and custom BuildListener X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: newchanged X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Ant X-Bugzilla-Component: Core X-Bugzilla-Keywords: X-Bugzilla-Severity: critical X-Bugzilla-Who: greg.schueler+bugzilla.asf@gmail.com X-Bugzilla-Status: NEW X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: notifications@ant.apache.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Thu, 12 Jun 2008 11:28:53 -0700 (PDT) X-Virus-Checked: Checked by ClamAV on apache.org https://issues.apache.org/bugzilla/show_bug.cgi?id=45194 Summary: deadlock with parallel task and custom BuildListener Product: Ant Version: 1.7.0 Platform: All OS/Version: All Status: NEW Severity: critical Priority: P2 Component: Core AssignedTo: notifications@ant.apache.org ReportedBy: greg.schueler+bugzilla.asf@gmail.com If a custom BuildListener retrieves a project property value inside the messageLogged() method, this can cause a deadlock when the ParallelTask is used, even in simple cases. In essence: Project.log locks the Project instance, and build listeners that access synchronized PropertyHelper methods will then lock the PropertyHelper instance: lock(Project) -> lock(PropertyHelper). The race occurs when another thread calls a synchronized method in PropertyHelper (e.g. Project.getProperty()) since many of the PropertyHelper methods call project.log: lock(PropertyHelper) -> lock(Project). Perhaps this is a caveat of using the Parallel task, but I think that accessing project properties (read-only) inside BuildListener.messageLogged should be made safe in this situation, since this can occur in the simplest usage of the parallel task. This is a race condition on the Project object and its PropertyHelper instance: fireMessageLoggedEvent in Project locks the Project prior to notifying BuildListeners. And the synchronized method PropertyHelper.setNewProperty() can call Project.log which invokes fireMessageLoggedEvent which locks the Project. Thus if a BuildListener invokes the synchronized method PropertyHelper.getProperty() it will attempt to lock the PropertyHelper, causing a race condition if two threads are running. 1. Project.fireMessageLoggedEvent -> synchronized(Project) -> BuildListener.messageLogged -> synchronized PropertyHelper.getProperty() 2. synchronized PropertyHelper.setNewProperty -> Project.log -> Project.fireMessageLoggedEvent -> synchronized(Project) This can be reproduced with a simple task with a few threads that just set property values and use the task. Additionally, running ant in debug mode will cause extra Project.log() calls inside PropertyHelper.setProperty() which also may trigger deadlock. Perhaps the solution is to remove the calls to project.log inside the synchronized methods of PropertyHelper? Otherwise there should be a lock on the Project instance prior to calling any of PropertyHelper's synchronized methods. Running the following build with the custom TestBL BuildListener reaches deadlock after a few attempts: TestBL.java: import org.apache.tools.ant.BuildListener; import org.apache.tools.ant.BuildEvent; public class TestBL implements BuildListener{ public void messageLogged(BuildEvent event) { String blahval = event.getProject().getProperty("blah"); String blahval2 = event.getProject().getProperty("blah2"); String blahval3 = event.getProject().getProperty("blah3"); String blahval4 = event.getProject().getProperty("blah"); String blahval5 = event.getProject().getProperty("blah2"); String blahval6 = event.getProject().getProperty("blah3"); String blahval7= event.getProject().getProperty("blah"); String blahval8 = event.getProject().getProperty("blah2"); String blahval9 = event.getProject().getProperty("blah3"); } public void buildStarted(BuildEvent event) { } public void buildFinished(BuildEvent event) { } public void targetStarted(BuildEvent event) { } public void targetFinished(BuildEvent event) { } public void taskStarted(BuildEvent event) { } public void taskFinished(BuildEvent event) { } } build.xml: This is a test 1: ${blah} This is a test 2: ${blah2} This is a test 2: ${blah2} This is a test 2: ${blah2} This is a test 3: ${blah3} This is a test 3: ${blah3} This is a test 3: ${blah3} $ javac -classpath ant.jar TestBL.java $ ant -lib . -listener TestBL -f build.xml -- Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug.