Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-702

LoggerConfig#waitForCompletion is not thread safe

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Critical
    • Resolution: Fixed
    • 2.0-rc2
    • 2.4
    • Core
    • None

    Description

      This is in trunk, svn commit 1608156

      LoggerConfig#waitForCompletion uses an AtomicInteger counter to try to detect if there are any calls currently executing the log(Event) method, but it does not do so in a thread safe manner. Consider two threads A and B, where Thread A is calling clearAppenders(), and Thread B is calling log(Event),

      Thread A  loggerConfig.clearAppenders()
      Thread A  loggerConfig.waitForCompletion()
      Thread A  counter.get() //returns 0
      Thread A  //loggerConfig.waitForCompletion() returns
      
      Thread B  loggerConfig.log(Event)
      Thread B  counter.increment()
      
      Thread A  proceeds assuming no log calls are onging, but thread B is in the log method
      
      

      I'm not sure what the requirements are, but if the requirement is to not lose logging events, I think you need some sort of synchronization outside of the LoggerConfig object.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              sbridges Sean Bridges
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: