[
https://issues.apache.org/jira/browse/LOG4J2-2158?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16301514#comment-16301514
]
ASF GitHub Bot commented on LOG4J2-2158:
----------------------------------------
GitHub user Vampire opened a pull request:
https://github.com/apache/logging-log4j2/pull/139
LOG4J2-2158 make inherited log event context data immutable when using
CopyOnWriteThreadContextMap
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/Vampire/logging-log4j2 LOG4J2-2158
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/logging-log4j2/pull/139.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #139
----
commit 64cdddb2e3d811d5ca6cc635154427cfe630ba62
Author: Björn Kautler <bjoern@...>
Date: 2017-12-22T14:41:45Z
LOG4J2-2158 make inherited log event context data immutable when using
CopyOnWriteThreadContextMap
----
> ThreadContext map is cleared => entries are only available for one log event
> ----------------------------------------------------------------------------
>
> Key: LOG4J2-2158
> URL: https://issues.apache.org/jira/browse/LOG4J2-2158
> Project: Log4j 2
> Issue Type: Bug
> Affects Versions: 2.10.0
> Reporter: Björn Kautler
> Priority: Critical
>
> In
> {{org.apache.logging.log4j.core.impl.ThreadContextDataInjector.ForCopyOnWriteThreadContextMap.injectContextData}}
> without properties set, the result of
> {{ThreadContext.getThreadContextMap().getReadOnlyContextData()}} is returned
> which was saved in a variable called {{immutableCopy}}.
> {{org.apache.logging.log4j.core.impl.ReusableLogEventFactory.createEvent}}
> calls {{result.clear()}} on that context data when the next log event is
> created.
> Unfortunately the "immutable" copy is not immutable at all, but is cleared on
> the this call and all thread context map entries are lost.
> If I set a {{Property}} on all loggers in the config, then the thread context
> map entries are not cleared, because the internal string map is not given out
> but the entries copied, but that property is also logged then of course.
> If I instead set the system property {{log4j2.garbagefree.threadContextMap}},
> the thread context map entries are also not cleared, as then also the entries
> are copied and not the internal structure given out.
> From what I have seen, I'd say there is a {{immutableCopy.freeze()}} missing
> before the {{immutableCopy}} is returned inside the {{if}}-block.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)