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

Kevin Risden commented on KNOX-1165:
------------------------------------

This is easily reproducible with current master:

Tab 1
 # ./bin/ldap.sh start
 # ./bin/gateway.sh start
 # tail -f logs/gateway.log

Tab 2
 # edit conf/topologies/sandbox.xml to add the following to the authentication 
provider:
 ## 
{code:java}
<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>{code}

 # curl -iku guest:guest-password 
[https://localhost:8443/gateway/sandbox/webhdfs/v1/]
 ## Ignore any errors about service connectivity if you don't have the service 
running
 # cp conf/topologies/sandbox.xml conf/topologies/sandbox2.xml
 # curl -iku guest:guest-password 
[https://localhost:8443/gateway/sandbox2/webhdfs/v1/]
 # Check that there is an error about cache manager in gateway.log

CacheManager error from gateway.log

 
{code:java}
2018-11-16 09:35:29,841 ERROR env.EnvironmentLoader 
(EnvironmentLoader.java:initEnvironment(152)) - 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:
1. Use one of the CacheManager.create() static factory methods to reuse same 
CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name.
The source of the existing CacheManager is: InputStreamConfigurationSource 
[stream=sun.net.www.protocol.jar.JarURLConnection$JarURLInputStream@6e4c3b48]
at 
org.apache.shiro.cache.ehcache.EhCacheManager.ensureCacheManager(EhCacheManager.java:223)
at org.apache.shiro.cache.ehcache.EhCacheManager.init(EhCacheManager.java:198)
at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:45)
at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:40)
at 
org.apache.shiro.config.ReflectionBuilder$BeanConfigurationProcessor.execute(ReflectionBuilder.java:819)
at 
org.apache.shiro.config.ReflectionBuilder.buildObjects(ReflectionBuilder.java:278)
at 
org.apache.shiro.config.IniSecurityManagerFactory.buildInstances(IniSecurityManagerFactory.java:181)
at 
org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:139)
at 
org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:107)
at 
org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:98)
at 
org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:47)
at 
org.apache.shiro.config.IniFactorySupport.createInstance(IniFactorySupport.java:150)
at org.apache.shiro.util.AbstractFactory.getInstance(AbstractFactory.java:47)
at 
org.apache.shiro.web.env.IniWebEnvironment.createWebSecurityManager(IniWebEnvironment.java:293)
at 
org.apache.shiro.web.env.IniWebEnvironment.configure(IniWebEnvironment.java:119)
at org.apache.shiro.web.env.IniWebEnvironment.init(IniWebEnvironment.java:71)
at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:45)
at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:40)
at 
org.apache.shiro.web.env.EnvironmentLoader.createEnvironment(EnvironmentLoader.java:313)
at 
org.apache.shiro.web.env.EnvironmentLoader.initEnvironment(EnvironmentLoader.java:139)
at 
org.apache.shiro.web.env.EnvironmentLoaderListener.contextInitialized(EnvironmentLoaderListener.java:58)
at 
org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:957)
at 
org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:552)
at 
org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:922)
at 
org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:364)
at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1497)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1459)
at 
org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:852)
at 
org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:278)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:545)
at 
org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at 
org.apache.knox.gateway.GatewayServer.internalActivateArchive(GatewayServer.java:796)
at 
org.apache.knox.gateway.GatewayServer.internalActivateTopology(GatewayServer.java:780)
at org.apache.knox.gateway.GatewayServer.access$900(GatewayServer.java:114)
at 
org.apache.knox.gateway.GatewayServer$InternalTopologyListener.handleCreateDeployment(GatewayServer.java:903)
at 
org.apache.knox.gateway.GatewayServer$InternalTopologyListener.handleTopologyEvent(GatewayServer.java:858)
at 
org.apache.knox.gateway.services.topology.impl.DefaultTopologyService.notifyChangeListeners(DefaultTopologyService.java:398)
at 
org.apache.knox.gateway.services.topology.impl.DefaultTopologyService.reloadTopologies(DefaultTopologyService.java:372)
at 
org.apache.knox.gateway.services.topology.impl.DefaultTopologyService.onFileChange(DefaultTopologyService.java:605)
at 
org.apache.knox.gateway.services.topology.impl.DefaultTopologyService.onFileCreate(DefaultTopologyService.java:595)
at 
org.apache.commons.io.monitor.FileAlterationObserver.doCreate(FileAlterationObserver.java:389)
at 
org.apache.commons.io.monitor.FileAlterationObserver.checkAndNotify(FileAlterationObserver.java:344)
at 
org.apache.commons.io.monitor.FileAlterationObserver.checkAndNotify(FileAlterationObserver.java:303)
at 
org.apache.commons.io.monitor.FileAlterationMonitor.run(FileAlterationMonitor.java:183)
at java.lang.Thread.run(Thread.java:748)
Caused by: 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:
1. Use one of the CacheManager.create() static factory methods to reuse same 
CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name.
The source of the existing CacheManager is: InputStreamConfigurationSource 
[stream=sun.net.www.protocol.jar.JarURLConnection$JarURLInputStream@6e4c3b48]
at 
net.sf.ehcache.CacheManager.assertNoCacheManagerExistsWithSameName(CacheManager.java:529)
at net.sf.ehcache.CacheManager.init(CacheManager.java:374)
at net.sf.ehcache.CacheManager.<init>(CacheManager.java:339)
at 
org.apache.shiro.cache.ehcache.EhCacheManager.ensureCacheManager(EhCacheManager.java:212)
... 44 more{code}
 

> 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: Server
>    Affects Versions: 0.12.0, 0.13.0, 0.14.0, 1.0.0, 1.1.0
>         Environment: JDK 1.8
> CentOS-6 (64bit)
>            Reporter: Ernani Pereira de Mattos Junior
>            Assignee: Kevin Risden
>            Priority: Critical
>             Fix For: 1.3.0
>
>
> *Problem*
> Issue is described on the note "Error:Shiro environment initialization 
> failed" when starting Knox;
> {code:java}
> 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 {code}
> After implementing the solution of creating a new ehcache.xml and reference 
> as <ehcache name="knox-mytopology1"> we still see the issue:
> {code:java}
> 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: {code}
> *Steps to reproduce*
> When enabling the following parameters: 
> {code:java}
> <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>{code}
> *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]
>  * The Default constructor only builds the Object, and does not do much: 
>  * 
> {code:java}
> /**Default no argument constructor*/
>  public EhCacheManager() {
>  }{code}
>  * Accordingly with shiro documentation: 
>  ** 
> {code:java}
> /**
> 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. }{code}
>  * This is the head of the exception: The source of the existing CacheManager 
> is:
>  ** 
> {code:java}
> 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){code}
>  * Starting from KNOX-804, the KnoxCacheManager was introduced. 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
(v7.6.3#76005)

Reply via email to