Log4j 2
  1. Log4j 2
  2. LOG4J2-280

AsynchAppender's AsynchThread blocks Tomcat shutdown

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-beta4, 2.0-beta5, 2.0-beta6, 2.0-beta7
    • Fix Version/s: 2.0-beta8, 2.0-beta9
    • Component/s: None
    • Labels:
      None
    • Environment:

      Log4j 2.0 beta 4, Tomcat 6, Java 6 @ Mac OS X

      Description

      Since I added an AsynchAppender to my configuration (to send mails with errors asynchronously), my Tomcat refuses to shut down nicely. It always freezes on a line like this:
      ...
      Jun 11, 2013 6:57:04 PM org.apache.coyote.http11.Http11Protocol destroy
      INFO: Stopping Coyote HTTP/1.1 on http-8080
      Jun 11, 2013 6:57:04 PM org.apache.coyote.http11.Http11Protocol destroy
      INFO: Stopping Coyote HTTP/1.1 on http-8443

      At this point, there is a non-daemon thread called "Thread-2" that, if I kill, Tomcat stops nicely.

      I have traced this issue to the AsynchThread in AsynchAppender, and if I stop using it in my configuration, Tomcat stops nicely again.

      Could you tell me what additional information I may provide to help track down this issue?

        Activity

        Remko Popma made changes -
        Status Reopened [ 4 ] Resolved [ 5 ]
        Fix Version/s 2.0-beta9 [ 12324756 ]
        Resolution Fixed [ 1 ]
        Hide
        Remko Popma added a comment -

        Committed revision 1506290:
        Additional fix to make AsyncAppender threads daemon threads and improve their thread name.

        Show
        Remko Popma added a comment - Committed revision 1506290: Additional fix to make AsyncAppender threads daemon threads and improve their thread name.
        Hide
        Remko Popma added a comment -

        The simplest way to use AsyncLoggers would be to remove the Async appender from the config and set system property -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector

        Show
        Remko Popma added a comment - The simplest way to use AsyncLoggers would be to remove the Async appender from the config and set system property -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
        Hide
        Matej Vitásek added a comment -

        Thanks for the info, I will probably wait for the next version (it was some time since I understood the config enough ).

        Show
        Matej Vitásek added a comment - Thanks for the info, I will probably wait for the next version (it was some time since I understood the config enough ).
        Remko Popma made changes -
        Resolution Fixed [ 1 ]
        Status Resolved [ 5 ] Reopened [ 4 ]
        Hide
        Remko Popma added a comment -

        Ah... My mistake!
        Only AsyncLogger threads are daemon threads. I did not fix the AsyncAppender thread...
        I'll fix this soon, so it is in the next release.

        As a workaround, is it possible for you to use the AsyncLoggers instead of AsyncAppender?

        Show
        Remko Popma added a comment - Ah... My mistake! Only AsyncLogger threads are daemon threads. I did not fix the AsyncAppender thread... I'll fix this soon, so it is in the next release. As a workaround, is it possible for you to use the AsyncLoggers instead of AsyncAppender?
        Hide
        Matej Vitásek added a comment -

        Remko, I have just downloaded the beta8 bin and src from the project main page. I am looking into the org.apache.logging.log4j.core.appender.AsyncAppender class and don't see any setDaemon() calls in it. When I run the Tomcat I am still having the original problems.

        Show
        Matej Vitásek added a comment - Remko, I have just downloaded the beta8 bin and src from the project main page. I am looking into the org.apache.logging.log4j.core.appender.AsyncAppender class and don't see any setDaemon() calls in it. When I run the Tomcat I am still having the original problems.
        Hide
        Remko Popma added a comment -

        Matej, AsyncLogger threads are definitely daemon threads as of beta8.
        Their thread name is now "AsyncLogger-X" or "AsyncLoggerConfig-X" (where X is 1, 2, 3...)

        What is the issue you are seeing? Same as before? What is the thread name?

        Show
        Remko Popma added a comment - Matej, AsyncLogger threads are definitely daemon threads as of beta8. Their thread name is now "AsyncLogger-X" or "AsyncLoggerConfig-X" (where X is 1, 2, 3...) What is the issue you are seeing? Same as before? What is the thread name?
        Hide
        Matej Vitásek added a comment -

        As far as I can tell, the aforementioned fix is not present in beta8...

        Show
        Matej Vitásek added a comment - As far as I can tell, the aforementioned fix is not present in beta8...
        Hide
        Matej Vitásek added a comment -

        Thanks guys, I will test this as soon as beta8 is out (any idea about when it will be?).

        Show
        Matej Vitásek added a comment - Thanks guys, I will test this as soon as beta8 is out (any idea about when it will be?).
        Remko Popma made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Hide
        Remko Popma added a comment -

        Fixed in revision 1498051: threads used by the async loggers are now daemon threads so should not prevent the JVM from shutting down any more.

        Please verify and close.

        Show
        Remko Popma added a comment - Fixed in revision 1498051: threads used by the async loggers are now daemon threads so should not prevent the JVM from shutting down any more. Please verify and close.
        Remko Popma made changes -
        Affects Version/s 2.0-beta7 [ 12324400 ]
        Affects Version/s 2.0-beta6 [ 12324340 ]
        Affects Version/s 2.0-beta5 [ 12323970 ]
        Affects Version/s 2.0-beta4 [ 12323477 ]
        Fix Version/s 2.0-beta8 [ 12324575 ]
        Remko Popma made changes -
        Field Original Value New Value
        Assignee Remko Popma [ remkop@yahoo.com ]
        Hide
        Ralph Goers added a comment -

        Actually, the fix for this is most likely to have the AsyncThread constructor do

        this.setDaemon(true);

        Show
        Ralph Goers added a comment - Actually, the fix for this is most likely to have the AsyncThread constructor do this.setDaemon(true);
        Hide
        Thomas Neidhart added a comment -

        Could you provide a stacktrace of the thread that hangs? Looking at the code of the async appender, there is no apparent call that may block apart from the queue (but this is handled via the shutdown method).

        We could also issue a thread.interrupt() before the call to join, but I would still like to see the stacktrace first.

        Show
        Thomas Neidhart added a comment - Could you provide a stacktrace of the thread that hangs? Looking at the code of the async appender, there is no apparent call that may block apart from the queue (but this is handled via the shutdown method). We could also issue a thread.interrupt() before the call to join, but I would still like to see the stacktrace first.
        Hide
        Matej Vitásek added a comment -

        Remko, thanks for the advice. I have just tried using beta7, and I am getting the same behavior.

        Show
        Matej Vitásek added a comment - Remko, thanks for the advice. I have just tried using beta7, and I am getting the same behavior.
        Hide
        Remko Popma added a comment -

        A similar issue was fixed in beta6. Can you try again with the latest release, beta7, and let us know if the issue is still there?

        Show
        Remko Popma added a comment - A similar issue was fixed in beta6. Can you try again with the latest release, beta7, and let us know if the issue is still there?
        Matej Vitásek created issue -

          People

          • Assignee:
            Remko Popma
            Reporter:
            Matej Vitásek
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development