Ernani Pereira de Mattos Junior created KNOX-1165:
-----------------------------------------------------

             Summary: Knox - Another unnamed CacheManager already exists in the 
same VM.
                 Key: KNOX-1165
                 URL: https://issues.apache.org/jira/browse/KNOX-1165
             Project: Apache Knox
          Issue Type: Bug
          Components: KnoxSSO, Server
    Affects Versions: 0.12.0
         Environment: JDK 1.8
CentOS-6 (64bit)
            Reporter: Ernani Pereira de Mattos Junior
            Priority: Critical


PROBLEM: 
Issue is described on the note ""Error:Shiro environment initialization failed" 
when starting KNOX"; 
 
ERROR env.EnvironmentLoader (EnvironmentLoader.java:initEnvironment(146)) - 
Shiro environment initialization failed 
org.apache.shiro.cache.CacheException: net.sf.ehcache.CacheException: Another 
unnamed CacheManager already exists in the same VM. Please provide unique names 
for each CacheManager in the config or do one of following: 

After implementing the solution of creating a new ehcache.xml and reference as 
<ehcache name="knox-mytopology1"> we still see the issue: 

Caused by: net.sf.ehcache.CacheException: Another CacheManager with same name 
'knox-tp' already exists in the same VM. Please provide unique names for each 
CacheManager in the config or do one of following:

STEPS TO REPRODUCE: 
When enabling the following parameters: 

<param> 
<name>main.cacheManager</name> 
<value>org.apache.shiro.cache.ehcache.EhCacheManager</value> 
</param> 
<param> 
<name>main.securityManager.cacheManager</name> 
<value>$cacheManager</value> 
</param> 
<param> 
<name>main.ldapRealm.authenticationCachingEnabled</name> 
<value>true</value> 
</param> 


MORE INFO: 
This KNOX-804 was open to solve this same issue but is not documented anywhere, 
but we can see the coding changes in GitHub.

-> The issue seems to be a racing condition on the Shiro lib class, in which 
depending on the processing power of the server there are two threads within 
the same "if" statement;

ref: 
https://github.com/apache/shiro/blob/master/support/ehcache/src/main/java/org/apache/shiro/cache/ehcache/EhCacheManager.java
 

1. The Default constructor only builds the Object, and does not do much: 
/** 
* Default no argument constructor 
*/ 
public EhCacheManager() { 
} 


2. Accordingly with shiro documentation: 
/** 
* Initializes this instance. 
* <p/> 
* If a {@link #setCacheManager CacheManager} has been 
* explicitly set (e.g. via Dependency Injection or programmatically) prior to 
calling this 
* method, this method does nothing. 
* <p/> 
* However, if no {@code CacheManager} has been set, the default Ehcache 
singleton will be initialized, where 
* Ehcache will look for an {@code ehcache.xml} file at the root of the 
classpath. If one is not found, 
* Ehcache will use its own failsafe configuration file. 
* <p/> 
* Because Shiro cannot use the failsafe defaults (fail-safe expunges cached 
objects after 2 minutes, 
* something not desirable for Shiro sessions), this class manages an internal 
default configuration for 
* this case. 
* 
* @throws org.apache.shiro.cache.CacheException 
* if there are any CacheExceptions thrown by EhCache. 
* @see net.sf.ehcache.CacheManager#create 
*/ 
public final void init() throws CacheException { 
ensureCacheManager(); 
} 

private net.sf.ehcache.CacheManager ensureCacheManager() { 
***It fails in here. 
} 


2.1 This is the head of the exception: 
The source of the existing CacheManager is: InputStreamConfigurationSource 
[stream=java.io.BufferedInputStream@675ffd1d] 
at 
org.apache.shiro.cache.ehcache.EhCacheManager.ensureCacheManager(EhCacheManager.java:224)
 
at org.apache.shiro.cache.ehcache.EhCacheManager.init(EhCacheManager.java:199) 
at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:45) 
at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:40) 


3. Starting from Knox-804, the KnoxCacheManager was introduced. 
public class KnoxCacheManager extends EhCacheManager { 
+ 
+ public KnoxCacheManager() { 
+ setCacheManager(net.sf.ehcache.CacheManager.create()); 
+ } 
+} 

*Remember that Init() will do nothing if anything in case the setCacheManager 
is explicitly set. 

ref: 
https://github.com/apache/knox/commit/f9d8e07d768459240c8665f139cc140575dc5216





--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to