Log4j 2
  1. Log4j 2
  2. LOG4J2-705

Async logger loses thread context stack for events


    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-rc2
    • Fix Version/s: 2.0
    • Component/s: Core
    • Labels:


      I've enabled the async logger and created some log message with values in thread context stack. However, the logged message does not contain any of these items.

      Looking at the sources, it seems that AsyncLogger.logMessage() needs to clone the stack instead of using ThreadContext.getImmutableStack() (line 260). This is because getImmutableStack() method returns the same stack as original - getting the real one from thread local storage. So when passed to another thread (as async does), the same stack "looks" into different thread and returns empty list. It is even possible to break this "immutable" stack when you create your own appender and use ThreadContext.push() in append() method. This will affect the message being logged.

      Simple solution is to replace getImmutableStack() method in AsyncLogger.logMessage() (line 260) with ThreadContext.cloneStack(). But I'm not sure if this is the right way.


        Martin Frydl created issue -
        Remko Popma made changes -
        Field Original Value New Value
        Assignee Remko Popma [ remkop@yahoo.com ]
        Martin Frydl made changes -
        Attachment async-context-test.zip [ 12655217 ]
        Remko Popma made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Remko Popma made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        Fix Version/s 2.0 [ 12324757 ]
        Resolution Fixed [ 1 ]
        Martin Frydl made changes -
        Status Resolved [ 5 ] Closed [ 6 ]


          • Assignee:
            Remko Popma
            Martin Frydl
          • Votes:
            0 Vote for this issue
            2 Start watching this issue


            • Created: