[JBoss JIRA] (ISPN-9917) JCachingProvider should not use weak ClassLoader references
by Dan Berindei (Jira)
[ https://issues.jboss.org/browse/ISPN-9917?page=com.atlassian.jira.plugin.... ]
Dan Berindei updated ISPN-9917:
-------------------------------
Description:
The idea behind {{WeakClassLoader}} is that we want users to be able to use {{Caching.getCachingProvider().getCacheManager()}} and not worry about closing the cache manager: instead Infinispan will close the manager when there are no more references to the provided {{ClassLoader}}.
In order to close the manager automatically, {{AbstractJCachingProvider}} maintains a {{WeakHashMap}} of classloaders to managers, and if the cache manager had a strong reference to the classloader, the {{WeakHashMap}} entry would never be collected. However, this approach causes problems when a test creates a temporary {{ClassLoader}} instance and calls {{Caching.getCachingProvider().getCacheManager(tempClassLoader)}}, because the JVM is free to collect {{tempClassLoader}} immediately after it's used to create the {{WeakClassLoader}}. This can cause failures in the jcache tck with the IBM JDK:
{noformat}
[OK: 268, KO: 3, SKIP: 0] Test failed: CachingProviderTest.closeCacheManagerByURIAndClassLoader
org.infinispan.commons.CacheConfigurationException: org.infinispan.commons.CacheException: Unable to construct a GlobalComponentRegistry!
at org.infinispan.manager.DefaultCacheManager.<init>(DefaultCacheManager.java:344)
at org.infinispan.jcache.embedded.JCacheManager.<init>(JCacheManager.java:70)
at org.infinispan.jcache.embedded.JCachingProvider.createCacheManager(JCachingProvider.java:46)
at org.infinispan.jcache.AbstractJCachingProvider.getCacheManager(AbstractJCachingProvider.java:67)
at org.jsr107.tck.spi.CachingProviderTest.closeCacheManagerByURIAndClassLoader(CachingProviderTest.java:175)
Caused by: org.infinispan.commons.CacheException: Unable to construct a GlobalComponentRegistry!
at org.infinispan.factories.GlobalComponentRegistry.<init>(GlobalComponentRegistry.java:164)
at org.infinispan.manager.DefaultCacheManager.<init>(DefaultCacheManager.java:329)
... 39 more
Caused by: org.infinispan.commons.CacheConfigurationException: Unable to inject dependencies for component class org.infinispan.notifications.cachemanagerlistener.CacheManagerNotifierImpl, path org.infinispan.notifications.cachemanagerlistener.CacheManagerNotifier (a org.infinispan.notifications.cachemanagerlistener.CacheManagerNotifierImpl)
at org.infinispan.factories.impl.BasicComponentRegistryImpl.performInjection(BasicComponentRegistryImpl.java:286)
at org.infinispan.factories.impl.BasicComponentRegistryImpl.wireWrapper(BasicComponentRegistryImpl.java:176)
at org.infinispan.factories.impl.BasicComponentRegistryImpl.registerComponent(BasicComponentRegistryImpl.java:360)
at org.infinispan.factories.GlobalComponentRegistry.<init>(GlobalComponentRegistry.java:120)
... 40 more
Caused by: org.infinispan.commons.CacheException: ClassLoader reference was garbage collected
at org.infinispan.jcache.embedded.WeakClassLoader.requireClassLoader(WeakClassLoader.java:49)
at org.infinispan.jcache.embedded.WeakClassLoader.findClass(WeakClassLoader.java:30)
at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:925)
at java.lang.ClassLoader.loadClass(ClassLoader.java:870)
at java.lang.ClassLoader.loadClass(ClassLoader.java:853)
at java.lang.Class.forNameImpl(Native Method)
at java.lang.Class.forName(Class.java:402)
at org.infinispan.commons.util.Util.loadClassStrict(Util.java:170)
at org.infinispan.commons.util.Util.loadClass(Util.java:122)
at org.infinispan.factories.impl.BasicComponentRegistryImpl.tryAutoInstantiation(BasicComponentRegistryImpl.java:249)
at org.infinispan.factories.impl.BasicComponentRegistryImpl.findFactory(BasicComponentRegistryImpl.java:202)
at org.infinispan.factories.impl.BasicComponentRegistryImpl.getComponent0(BasicComponentRegistryImpl.java:94)
at org.infinispan.factories.impl.BasicComponentRegistryImpl.getDependency(BasicComponentRegistryImpl.java:327)
at org.infinispan.factories.impl.BasicComponentRegistryImpl.setInjectionField(BasicComponentRegistryImpl.java:315)
at org.infinispan.factories.impl.BasicComponentRegistryImpl.performInjection(BasicComponentRegistryImpl.java:276)
... 43 more
{noformat}
was:
The idea behind {{WeakClassLoader}} is that we want users to be able to use {{Caching.getCachingProvider().getCacheManager()}} and not worry about closing the cache manager: instead Infinispan will close the manager when there are no more references to the provided {{ClassLoader}}.
In order to close the manager automatically, {{AbstractJCachingProvider}} maintains a {{WeakHashMap}} of classloaders to managers, and if the cache manager had a strong reference to the classloader, the {{WeakHashMap}} entry would never be collected.
> JCachingProvider should not use weak ClassLoader references
> -----------------------------------------------------------
>
> Key: ISPN-9917
> URL: https://issues.jboss.org/browse/ISPN-9917
> Project: Infinispan
> Issue Type: Bug
> Components: JCache
> Affects Versions: 10.0.0.Alpha3, 9.4.6.Final
> Reporter: Dan Berindei
> Assignee: Dan Berindei
> Priority: Major
> Fix For: 10.0.0.Beta1, 9.4.7.Final
>
>
> The idea behind {{WeakClassLoader}} is that we want users to be able to use {{Caching.getCachingProvider().getCacheManager()}} and not worry about closing the cache manager: instead Infinispan will close the manager when there are no more references to the provided {{ClassLoader}}.
> In order to close the manager automatically, {{AbstractJCachingProvider}} maintains a {{WeakHashMap}} of classloaders to managers, and if the cache manager had a strong reference to the classloader, the {{WeakHashMap}} entry would never be collected. However, this approach causes problems when a test creates a temporary {{ClassLoader}} instance and calls {{Caching.getCachingProvider().getCacheManager(tempClassLoader)}}, because the JVM is free to collect {{tempClassLoader}} immediately after it's used to create the {{WeakClassLoader}}. This can cause failures in the jcache tck with the IBM JDK:
> {noformat}
> [OK: 268, KO: 3, SKIP: 0] Test failed: CachingProviderTest.closeCacheManagerByURIAndClassLoader
> org.infinispan.commons.CacheConfigurationException: org.infinispan.commons.CacheException: Unable to construct a GlobalComponentRegistry!
> at org.infinispan.manager.DefaultCacheManager.<init>(DefaultCacheManager.java:344)
> at org.infinispan.jcache.embedded.JCacheManager.<init>(JCacheManager.java:70)
> at org.infinispan.jcache.embedded.JCachingProvider.createCacheManager(JCachingProvider.java:46)
> at org.infinispan.jcache.AbstractJCachingProvider.getCacheManager(AbstractJCachingProvider.java:67)
> at org.jsr107.tck.spi.CachingProviderTest.closeCacheManagerByURIAndClassLoader(CachingProviderTest.java:175)
> Caused by: org.infinispan.commons.CacheException: Unable to construct a GlobalComponentRegistry!
> at org.infinispan.factories.GlobalComponentRegistry.<init>(GlobalComponentRegistry.java:164)
> at org.infinispan.manager.DefaultCacheManager.<init>(DefaultCacheManager.java:329)
> ... 39 more
> Caused by: org.infinispan.commons.CacheConfigurationException: Unable to inject dependencies for component class org.infinispan.notifications.cachemanagerlistener.CacheManagerNotifierImpl, path org.infinispan.notifications.cachemanagerlistener.CacheManagerNotifier (a org.infinispan.notifications.cachemanagerlistener.CacheManagerNotifierImpl)
> at org.infinispan.factories.impl.BasicComponentRegistryImpl.performInjection(BasicComponentRegistryImpl.java:286)
> at org.infinispan.factories.impl.BasicComponentRegistryImpl.wireWrapper(BasicComponentRegistryImpl.java:176)
> at org.infinispan.factories.impl.BasicComponentRegistryImpl.registerComponent(BasicComponentRegistryImpl.java:360)
> at org.infinispan.factories.GlobalComponentRegistry.<init>(GlobalComponentRegistry.java:120)
> ... 40 more
> Caused by: org.infinispan.commons.CacheException: ClassLoader reference was garbage collected
> at org.infinispan.jcache.embedded.WeakClassLoader.requireClassLoader(WeakClassLoader.java:49)
> at org.infinispan.jcache.embedded.WeakClassLoader.findClass(WeakClassLoader.java:30)
> at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:925)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:870)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:853)
> at java.lang.Class.forNameImpl(Native Method)
> at java.lang.Class.forName(Class.java:402)
> at org.infinispan.commons.util.Util.loadClassStrict(Util.java:170)
> at org.infinispan.commons.util.Util.loadClass(Util.java:122)
> at org.infinispan.factories.impl.BasicComponentRegistryImpl.tryAutoInstantiation(BasicComponentRegistryImpl.java:249)
> at org.infinispan.factories.impl.BasicComponentRegistryImpl.findFactory(BasicComponentRegistryImpl.java:202)
> at org.infinispan.factories.impl.BasicComponentRegistryImpl.getComponent0(BasicComponentRegistryImpl.java:94)
> at org.infinispan.factories.impl.BasicComponentRegistryImpl.getDependency(BasicComponentRegistryImpl.java:327)
> at org.infinispan.factories.impl.BasicComponentRegistryImpl.setInjectionField(BasicComponentRegistryImpl.java:315)
> at org.infinispan.factories.impl.BasicComponentRegistryImpl.performInjection(BasicComponentRegistryImpl.java:276)
> ... 43 more
> {noformat}
--
This message was sent by Atlassian Jira
(v7.12.1#712002)
5 years, 11 months
[JBoss JIRA] (ISPN-9917) JCachingProvider should not use weak ClassLoader references
by Dan Berindei (Jira)
Dan Berindei created ISPN-9917:
----------------------------------
Summary: JCachingProvider should not use weak ClassLoader references
Key: ISPN-9917
URL: https://issues.jboss.org/browse/ISPN-9917
Project: Infinispan
Issue Type: Bug
Components: JCache
Affects Versions: 9.4.6.Final, 10.0.0.Alpha3
Reporter: Dan Berindei
Assignee: Dan Berindei
Fix For: 10.0.0.Beta1, 9.4.7.Final
The idea behind {{WeakClassLoader}} is that we want users to be able to use {{Caching.getCachingProvider().getCacheManager()}} and not worry about closing the cache manager: instead Infinispan will close the manager when there are no more references to the provided {{ClassLoader}}.
In order to close the manager automatically, {{AbstractJCachingProvider}} maintains a {{WeakHashMap}} of classloaders to managers, and if the cache manager had a strong reference to the classloader, the {{WeakHashMap}} entry would never be collected.
--
This message was sent by Atlassian Jira
(v7.12.1#712002)
5 years, 11 months