Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-128

race condition when creating log directory in multithreaded environment

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.1.3
    • Component/s: logback-core
    • Labels:
      None

      Description

      There is a race condition when multiple threads are trying to create the same parent log directory in logback:

      java.lang.IllegalStateException: /path/to/log/dir/2010/2010_12/2010_12_08/file.log should not have existing parent directory
              at ch.qos.logback.core.util.FileUtil.createMissingParentDirectories(FileUtil.java:43) ~[logback-core-0.9.26.jar:na]
              at ch.qos.logback.core.FileAppender.openFile(FileAppender.java:156) ~[logback-core-0.9.26.jar:na]
              at ch.qos.logback.core.FileAppender.start(FileAppender.java:115) ~[logback-core-0.9.26.jar:na]
      [...]
      

      It is completely ok for the check to start if the directory is there and then have the directory appear when we actually come around to creating it. This is because you may have multiple threads wanting to log to the same directory, and if they try to create the dir at the same time one will succeed and one will have it already created. This happens for instance in the case above where a new dir is created at midnight every day, and two threads log at the same time.

      Will attach a patch that fixes the problem.

        Attachments

          Activity

            People

            • Assignee:
              tony19 Tony Trinh
              Reporter:
              zakalwe Mats Henrikson
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: