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

PatternLayoutBase concurrent access race condition

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 1.1.11
    • 1.1.10
    • logback-core
    • None

    Description

      I found the race condition in the Logback:

       

      PatternLayoutBase.java
      StringBuilder recycledStringBuilder = new StringBuilder(INTIAL_STRING_BUILDER_SIZE);
      ...
      protected String writeLoopOnConverters(E event) \{
              StringBuilder strBuilder = getRecycledStringBuilder();
      ...
      }
      
          private StringBuilder getRecycledStringBuilder() \{
              if (recycledStringBuilder.length() > MAX_STRING_BUILDER_LENGTH) \{
                  recycledStringBuilder = new StringBuilder(INTIAL_STRING_BUILDER_SIZE);
              }
              recycledStringBuilder.setLength(0);
              return recycledStringBuilder;
          }
      

       

      So, when we have multi-threaded appender, we end up with the issue writing to the same StringBuilder concurrently.

      See this consequent commits in Logback:
      https://github.com/qos-ch/logback/commit/6ddea70a42055adb3a9d1dd844c2f2bb0333353b
      https://github.com/qos-ch/logback/commit/4938ee75971c9003e7a12ce0dadbadae8dd263c5

      The problem with the last one that it isn't backported to 1.1.x.

       

      Since the fix has been done in master, please, consider to backport it into 1.1.x.

       

      See https://github.com/spring-projects/spring-boot/issues/8354 for more info.

      Attachments

        Activity

          People

            ceki Ceki Gülcü
            abilan Artem Bilan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: