[logback-dev] [JIRA] Created: (LBCLASSIC-264) MDC of parent thread can be wiped from child thread

Iwein Fuld (JIRA) noreply-jira at qos.ch
Fri May 6 11:35:51 CEST 2011


MDC of parent thread can be wiped from child thread
---------------------------------------------------

                 Key: LBCLASSIC-264
                 URL: http://jira.qos.ch/browse/LBCLASSIC-264
             Project: logback-classic
          Issue Type: Bug
    Affects Versions: 0.9.28
            Reporter: Iwein Fuld
            Assignee: Logback dev list


In our web framework we're using the MDC, but because we use multiple rendering threads we need to copy context from one thread to another. With log4j this worked fine, with logback it doesn't. It seems that there is an issue at least with setContextMap, which can influence the MDC in other (non child) threads.

I've reproduced one such issue in a small project: 

https://github.com/iwein/logback-testdrive

Look at this testcase in particular:

{code}
    @Test
    public void shouldCopyContextToOtherThread() throws Exception {
        final AtomicReference<Map> contextMap = new AtomicReference<Map>();

        MDC.put("first", "Dorothy");
        MDC.put("last", "Parker");

        contextMap.set(MDC.getCopyOfContextMap());

        //some context is set in a different thread
        Executors.newSingleThreadExecutor().execute(new Runnable() {
            public void run() {
                //not needed, but shouldn't break anything in the parent right?
                MDC.setContextMap(contextMap.get());
                logger.info("Check enclosed.");
            }
        });

        //If I don't do this I have lost my context. That seems wrong..
        //MDC.setContextMap(contextMap.get());

        logger.debug("The most beautiful two words in English.");
    }
{code}

I'll try to reproduce the issue with some sibling threads for the heck of it, but I think the above already illustrates the problem.


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the logback-dev mailing list