You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "ppkarwasz (via GitHub)" <gi...@apache.org> on 2024/04/25 18:57:31 UTC

[I] Removing all keys from `ThreadContextMap` does not clear the `ThreadLocal` (logging-log4j2)

ppkarwasz opened a new issue, #2523:
URL: https://github.com/apache/logging-log4j2/issues/2523

   The implementations of [`ThreadContextMap#remove`](https://logging.apache.org/log4j/2.x/javadoc/log4j-api/org/apache/logging/log4j/spi/ThreadContextMap#remove(java.lang.String)) and [`CleanableThreadContextMap#removeAll`](https://logging.apache.org/log4j/2.x/javadoc/log4j-api/org/apache/logging/log4j/spi/CleanableThreadContextMap#removeAll(java.lang.Iterable)) in the `DefaultThreadContextMap` and `CopyOnWriteSortedArrayThreadContextMap` implementations do not clear the underlying `ThreadLocal`, after all keys have been removed from the context map.
   
   This issue prevents `CopyOnWriteSortedArrayThreadContextMap` to be safely used in a web application, if code like this is used:
   
   ```java
   ThreadContext.put("key", "value");
   try {
       ...
   } finally {
       ThreadContext.remove("key");
   }
   ```
   
   **Remark**: this issue does not affect the `GarbageFreeSortedArrayThreadContextMap` implementation, since leaving a non-null value of `ThreadContext` is part of its garbage-free design.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org