[ 
https://issues.apache.org/jira/browse/LOG4J2-3427?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17508600#comment-17508600
 ] 

Piotr Karwasz commented on LOG4J2-3427:
---------------------------------------

Actually I think there are at the moment two problems in the way, e.g. 
{{PropertiesUtil}} work in a servlet environment. Assuming there is a copy of 
{{log4j-api}} in both the web application and the server classloaders:
 # the copy in the web application's classloader will fail to detect *any* 
property source: it will find the classes in the parent classloader and throw 
an exception, because they don't extend {{{}PropertySource{}}}.
 # the copy in the server's classloader (which can be reached if the webapp 
does not have {{{}log4j-api{}}}) will use the context classloader to find 
property sources in the webapp classloader and binding them to a static field. 
This causes a memory leak.

> ServiceLoader usage in a servlet environment
> --------------------------------------------
>
>                 Key: LOG4J2-3427
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3427
>             Project: Log4j 2
>          Issue Type: Improvement
>            Reporter: Piotr Karwasz
>            Assignee: Piotr Karwasz
>            Priority: Major
>
> It is fair to assume that a servlet container like Tomcat might contain 
> multiple copies of Log4j 2.x:
>  * a copy of Log4j 2.x can be used as logging provider for the entire server,
>  * each web application can contain another copy of Log4j 2.x
> One of the shortcomings of {{ServiceLoader}} is that it detects services in 
> both the web application's and server's classloader, but only those in the 
> web application are usable: those in the server's classloader can not extend 
> the service class contained in the application's classloader.
> A typical usage of {{ServiceLoader}} to find all instances of a certain 
> service can therefore end up in a {{{}ServiceConfigurationError{}}}. Those 
> are caught in Log4j 2.x, but usually end up in all services (also the viable 
> ones) being {*}discarded{*}.
> Hence a tool is necessary to only discard those services, which are contained 
> in the server's classloader.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to