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

MDC.clear() in child thread improperly affects parent.

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 0.9.28
    • Fix Version/s: 0.9.29
    • Component/s: logback-classic
    • Labels:
      None
    • Environment:

      JDK 1.6.0_21

      Description

      I want to upgrade logback to 0.9.28 but one of my unit tests caught this bug in the LogbackMDCAdapter. Basically, if a child thread clears the MDC, the parent thread's copy is cleared as well. This simple unit test illustrates the problem.

      import org.junit.Test;
      import org.slf4j.MDC;

      /**

      • Demonstrates a bug in LogbackMDCAdapter. The clear() executed by the child thread should not affect the parent.
        */
        public class MDCTest {

      @Test
      public void testBug() throws InterruptedException {
      MDC.put("foo", "bar");
      assertEquals("bar", MDC.get("foo"));

      Thread clearer = new Thread() {
      @Override
      public void run()

      { MDC.clear(); assertNull(MDC.get("foo")); }

      };

      clearer.start();
      clearer.join();
      //Fails
      assertEquals("bar", MDC.get("foo"));
      }
      }

        Attachments

          Activity

            People

            • Assignee:
              ceki Ceki Gülcü
              Reporter:
              tbecker Tommy Becker
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: