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

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


    [ http://jira.qos.ch/browse/LBCLASSIC-264?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12007#action_12007 ] 

Iwein Fuld commented on LBCLASSIC-264:
--------------------------------------

Added a sibling test here: https://github.com/iwein/logback-testdrive/commit/5d7a24a44ad4f3be99e794f192dd6c24b7a3c28d

It seems that LogbackMDCAdapter doesn't use CopyOnInheritThreadLocal while the field name suggest that it was intended to do so. If I feel inspired this weekend I might crank out a patch.

> 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: Ceki Gulcu
>
> 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