You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2008/07/11 17:45:53 UTC

svn commit: r675993 - in /ant/core/trunk: CONTRIBUTORS WHATSNEW contributors.xml src/main/org/apache/tools/ant/XmlLogger.java

Author: bodewig
Date: Fri Jul 11 08:45:53 2008
New Revision: 675993

URL: http://svn.apache.org/viewvc?rev=675993&view=rev
Log:
XmlLogger could lose messages when parallel is used.  PR 25734.  Based on analysis and patch by Craig Sandvik

Modified:
    ant/core/trunk/CONTRIBUTORS
    ant/core/trunk/WHATSNEW
    ant/core/trunk/contributors.xml
    ant/core/trunk/src/main/org/apache/tools/ant/XmlLogger.java

Modified: ant/core/trunk/CONTRIBUTORS
URL: http://svn.apache.org/viewvc/ant/core/trunk/CONTRIBUTORS?rev=675993&r1=675992&r2=675993&view=diff
==============================================================================
Binary files - no diff available.

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=675993&r1=675992&r2=675993&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Jul 11 08:45:53 2008
@@ -101,6 +101,9 @@
    parts, some result sets wouldn't get printed.
    Bugzilla Report 32168.
 
+ * XmlLogger could lose messages if <parallel> is used.
+   Bugzilla Report 25734.
+
 Other changes:
 --------------
 

Modified: ant/core/trunk/contributors.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/contributors.xml?rev=675993&r1=675992&r2=675993&view=diff
==============================================================================
--- ant/core/trunk/contributors.xml (original)
+++ ant/core/trunk/contributors.xml Fri Jul 11 08:45:53 2008
@@ -200,6 +200,10 @@
     <last>Ryan</last>
   </name>
   <name>
+    <first>Craig</first>
+    <last>Sandvik</last>
+  </name>
+  <name>
     <first>Curtis</first>
     <last>White</last>
   </name>

Modified: ant/core/trunk/src/main/org/apache/tools/ant/XmlLogger.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/XmlLogger.java?rev=675993&r1=675992&r2=675993&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/XmlLogger.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/XmlLogger.java Fri Jul 11 08:45:53 2008
@@ -33,6 +33,7 @@
 import org.apache.tools.ant.util.StringUtils;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+import org.w3c.dom.Node;
 import org.w3c.dom.Text;
 
 /**
@@ -172,7 +173,7 @@
             Text errText = doc.createCDATASection(StringUtils.getStackTrace(t));
             Element stacktrace = doc.createElement(STACKTRACE_TAG);
             stacktrace.appendChild(errText);
-            buildElement.element.appendChild(stacktrace);
+            synchronizedAppend(buildElement.element, stacktrace);
         }
         String outFilename = event.getProject().getProperty("XmlLogger.file");
         if (outFilename == null) {
@@ -267,9 +268,10 @@
                 }
             }
             if (parentElement == null) {
-                buildElement.element.appendChild(targetElement.element);
+                synchronizedAppend(buildElement.element, targetElement.element);
             } else {
-                parentElement.element.appendChild(targetElement.element);
+                synchronizedAppend(parentElement.element,
+                                   targetElement.element);
             }
         }
         targets.remove(target);
@@ -320,9 +322,9 @@
             targetElement = (TimedElement) targets.get(target);
         }
         if (targetElement == null) {
-            buildElement.element.appendChild(taskElement.element);
+            synchronizedAppend(buildElement.element, taskElement.element);
         } else {
-            targetElement.element.appendChild(taskElement.element);
+            synchronizedAppend(targetElement.element, taskElement.element);
         }
         Stack threadStack = getStack();
         if (!threadStack.empty()) {
@@ -394,7 +396,7 @@
             Text errText = doc.createCDATASection(StringUtils.getStackTrace(ex));
             Element stacktrace = doc.createElement(STACKTRACE_TAG);
             stacktrace.appendChild(errText);
-            buildElement.element.appendChild(stacktrace);
+            synchronizedAppend(buildElement.element, stacktrace);
         }
         Text messageText = doc.createCDATASection(event.getMessage());
         messageElement.appendChild(messageText);
@@ -411,9 +413,9 @@
             parentElement = (TimedElement) targets.get(target);
         }
         if (parentElement != null) {
-            parentElement.element.appendChild(messageElement);
+            synchronizedAppend(parentElement.element, messageElement);
         } else {
-            buildElement.element.appendChild(messageElement);
+            synchronizedAppend(buildElement.element, messageElement);
         }
     }
 
@@ -459,4 +461,10 @@
     public void setErrorPrintStream(PrintStream err) {
     }
 
+    private void synchronizedAppend(Node parent, Node child) {
+        synchronized(parent) {
+            parent.appendChild(child);
+        }
+    }
+
 }



Re: Logging and synchronization

Posted by Jeffrey E Care <ca...@us.ibm.com>.
Stefan Bodewig <bo...@apache.org> wrote on 07/17/2008 04:01:34 AM:

> > I spent a lot of time & effort writing a thread-safe logger for our
> > own internal use.
> 
> Sounds as if it was more painful than I had expected.

It's been quite a while, so my memory is a little hazy, but IIRC much of 
the effort was expended around features that are specific to our own 
Antlibs; if you strip out that code it's probably easier to do than I 
remember.

It's going to take a while to get this contribution cleared through IBM's 
IP attorneys, so don't expect to see anything for a few months.

____________________________________________________________________________________________ 

Jeffrey E. (Jeff) Care 
carej@us.ibm.com 
IBM WebSphere Application Server 
WAS Release Engineering 




Re: Logging and synchronization

Posted by Stefan Bodewig <bo...@apache.org>.
On Fri, 11 Jul 2008, Jeffrey E. Care <ca...@us.ibm.com> wrote:

> I spent a lot of time & effort writing a thread-safe logger for our
> own internal use.

Sounds as if it was more painful than I had expected.

> If there's sufficient interest I'd be willing to get the ball
> rolling on getting the contribution approved by our internal IP
> folks...

I'd be interested.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: Logging and synchronization

Posted by Jeffrey E Care <ca...@us.ibm.com>.
I spent a lot of time & effort writing a thread-safe logger for our own 
internal use. If there's sufficient interest I'd be willing to get the 
ball rolling on getting the contribution approved by our internal IP 
folks...

____________________________________________________________________________________________ 

Jeffrey E. (Jeff) Care 
carej@us.ibm.com 
IBM WebSphere Application Server 
WAS Release Engineering 







From:
Stefan Bodewig <bo...@apache.org>
To:
dev@ant.apache.org
Date:
07/11/2008 12:03 PM
Subject:
Logging and synchronization



On Fri, 11 Jul 2008, <bo...@apache.org> wrote:

> XmlLogger could lose messages when parallel is used.

Since DOM is not thread safe (something I didn't fully realize) our
XMLLogger implementation failed to add a few elements when parallel
was used.  I've now synchronized all appendChild calls and it seems to
work OK.

Of course this means XmlLogger will now be synchronized even if you
don't use parallel at all - or fork processes which could generate
messageLogged events from a separate thread, or do anything else that
happens on a separate thread.

Do you think it would be worth it if we added a SynchronizedXmlLogger
and ask people to use that if they intend to do multithreaded things?
Or do we just swallow the performance impact of synchronization?

BTW, all the other loggers are vulnerable to this as well.
DefaultLogger will happily mix log outputs of several messages - in
particular now that trunk no longer serializes the messageLogged
events.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org




Logging and synchronization

Posted by Stefan Bodewig <bo...@apache.org>.
On Fri, 11 Jul 2008, <bo...@apache.org> wrote:

> XmlLogger could lose messages when parallel is used.

Since DOM is not thread safe (something I didn't fully realize) our
XMLLogger implementation failed to add a few elements when parallel
was used.  I've now synchronized all appendChild calls and it seems to
work OK.

Of course this means XmlLogger will now be synchronized even if you
don't use parallel at all - or fork processes which could generate
messageLogged events from a separate thread, or do anything else that
happens on a separate thread.

Do you think it would be worth it if we added a SynchronizedXmlLogger
and ask people to use that if they intend to do multithreaded things?
Or do we just swallow the performance impact of synchronization?

BTW, all the other loggers are vulnerable to this as well.
DefaultLogger will happily mix log outputs of several messages - in
particular now that trunk no longer serializes the messageLogged
events.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org