You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by bu...@apache.org on 2007/10/08 08:20:45 UTC

DO NOT REPLY [Bug 43568] New: - Deadlock in Log4j when logging inside exception stack trace

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=43568>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=43568

           Summary: Deadlock in Log4j when logging inside exception stack
                    trace
           Product: Log4j
           Version: 1.2
          Platform: Sun
        OS/Version: Solaris
            Status: NEW
          Severity: major
          Priority: P1
         Component: Other
        AssignedTo: log4j-dev@logging.apache.org
        ReportedBy: kenny.moens.ext@nsn.com


- Log4j is configured with a RootLogger and a specific Logger for the package
com.siemens, both configured to use the same RollingFileAppender. 
- Thread 1: a class in the package X logs an exception outside the package X
- Thread 2: a class outside the package X tries to log another message 

ull description of deadlock: 
[T1]: Thread 1 acquires a lock on the specific Logger of package X
[T1]: As a consequence Thread 1 acquires a lock on the RollingFileAppender 
[T2]: Thread 2 wants to log something and as such acquires a lock on RootLogger.
[T2]: To perform the logging, Thread 2 waits to get a lock on the
RollingFileAppender 
[T1]: The logging of the exception in Thread 1 also wants to write stuff to the
log and as it is outside the X package wants a lock on the RootLogger which is
owned by Thread 2 already.

The problem occured with Apache Axis 1.4 which appearantly shows this behaviour
of logging during the generation of exception stack traces.

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

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


DO NOT REPLY [Bug 43568] - Deadlock in Log4j when logging inside exception stack trace

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=43568>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=43568


kenny.moens.ext@nsn.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|major                       |critical




-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

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


DO NOT REPLY [Bug 43568] - Deadlock in Log4j when logging inside exception stack trace

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=43568>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=43568


carnold@apache.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |LATER




------- Additional Comments From carnold@apache.org  2007-10-31 09:44 -------
log4j 1.2's architecture is such that any attempt to log from within the scope of a log4j method will 
potentially deadlock.  Eliminating the coarse-grained locking is a design goal for log4j 2.0, but it can't 
be done in log4j 1.2 without breaking appenders and layouts that depend on the current 
synchronization model.

This is typically encountered when the toString() member of the message parameter makes log4j calls.  
However, if an exception parameters printStackTrace(Writer) method makes log4j calls the same type of 
deadlock situation could arise.

The only potential remedy would be to prevent this situation from arising.  One way to prevent it would 
be to create a custom layout that suppresses the stack trace for the problematic exceptions (assuming 
that you are using a FileAppender or other derived from WriterAppender).  Something like:

public class MyPatternLayout extends PatternLayout {
    //
    //  returning false suppresses the default handling of 
    //    exceptions in WriterAppender
    public boolean ignoresThrowable() {
        return false;
    }
    private static boolean safeException(ThrowableInformation ti) {
         if (ti != null) {
             Throwable t = ti.getThrowable();
             if (t != null) {
                  if (t instanceof MyBadException1 ||
                      t instanceof MyBadException2) {
                      return false;
                  }
            }
            return true;
        }
        return false;
    }

    public String format(final LoggingEvent event) {
        String retval = super.format(event);
        if (safeException(event.getThrowableInfo()) {
             StringBuffer buf = new StringBuffer(retval);
             String[] trace = event.getThrowableStrRep();
             if (trace != null) {
                  for(int i = 0; i < trace.length; i++) {
                       buf.append(trace[i]);
                       buf.append(Layout.LINE_SEP);
                  }
             }
            retval = buf.toString();
       } else {
            //  as much info on the bad exception that you can get
            //     without triggering a log4j call
       }
}

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

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