[jboss-jira] [JBoss JIRA] (WFLY-1531) NullPointerException in InfinispanRegionFactory.applyConfiguration

jaikiran pai (JIRA) jira-events at lists.jboss.org
Fri Jun 14 23:49:54 EDT 2013


    [ https://issues.jboss.org/browse/WFLY-1531?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12781836#comment-12781836 ] 

jaikiran pai commented on WFLY-1531:
------------------------------------

>> From looking at the code, I'm not sure why org.hibernate.cache.infinispan.InfinispanRegionFactory.manager would be null

The problem isn't exactly in org.hibernate.cache.infinispan.InfinispanRegionFactory. The org.hibernate.cache.infinispan.InfinispanRegionFactory#start() method looks something like:

{code}
start() {
  manager = createCacheManager(...);
  ...
  callAMethodWhichDoesSomethingWithTheManagerWhichWeSetEarlier();
}

createCacheManager() {
  ..
  return CacheManagerWhichIsNeverNull();
}
{code}

So as can be seen there's no chance the manager can be null when callAMethodWhichDoesSomethingWithTheManagerWhichWeSetEarlier() is called, if org.hibernate.cache.infinispan.InfinispanRegionFactory is considered in isolation. However, the JPA integration code in AS7 ends up using a sub class of org.hibernate.cache.infinispan.InfinispanRegionFactory. It's org.jboss.as.jpa.hibernate4.infinispan.SharedInfinispanRegionFactory or even org.jboss.as.jpa.hibernate4.infinispan.InfinispanRegionFactory. Both these subclasses have an overridden implementation of createCacheManager() method which have the potential of returning null due to race conditions and that's exactly what happening from what I understand of the code. 

These overridden implementations of createCacheManager() call:

{code}
wrapper = Notification.startCache(Classification.INFINISPAN, cacheSettings);
return (EmbeddedCacheManager)wrapper.getValue();
{code}

The Notification.startCache() ultimately leads to org.jboss.as.jpa.processor.secondLevelCache.InfinispanCacheDeploymentListener#startCache() which does this:

{code}
/ need a shared cache for jpa applications
            serviceName = EmbeddedCacheManagerService.getServiceName(container);
            ServiceRegistry registry = CurrentServiceContainer.getServiceContainer();
            embeddedCacheManager = (EmbeddedCacheManager) registry.getRequiredService(serviceName).getValue();
{code}

So it uses the ServiceRegistry to pull out a required service and invokes getValue() on it. The service being looked up looks like this:

{code}
public class EmbeddedCacheManagerService implements Service<EmbeddedCacheManager> {

    private volatile EmbeddedCacheManager container;

    @Override
    public EmbeddedCacheManager getValue() {
        return this.container;
    }

    @Override
    public void start(StartContext context) {
        EmbeddedCacheManagerConfiguration config = this.config.getValue();
        this.container = new DefaultEmbeddedCacheManager(config.getGlobalConfiguration(), config.getDefaultCache());
...
    }
{code}

However, there's no dependency setup between this caller and the service which effectively means that the getValue() has chances of returning null. i.e. the getValue() gets invoked even before the service is started.

To summarize, this code path and the constructs involved here are missing relevant service dependencies which result in this race condition. I don't know much about the code involved, but at a minimal, I think the InfinispanCacheDeploymentListener#startCache() should be doing:

{code}
embeddedCacheManager = (EmbeddedCacheManager) registry.getRequiredService(serviceName).awaitValue(); // wait for the service to start
{code}

instead of:

{code}
embeddedCacheManager = (EmbeddedCacheManager) registry.getRequiredService(serviceName).getValue();
{code}

However, setting up proper dependencies if possible is the best solution, IMO.


 
                
> NullPointerException in InfinispanRegionFactory.applyConfiguration
> ------------------------------------------------------------------
>
>                 Key: WFLY-1531
>                 URL: https://issues.jboss.org/browse/WFLY-1531
>             Project: WildFly
>          Issue Type: Bug
>          Components: Test Suite
>    Affects Versions: 8.0.0.Alpha1
>            Reporter: jaikiran pai
>            Assignee: Scott Marlow
>         Attachments: log.txt
>
>
> An intermittent test failure on TeamCity has shown a NPE in the logs:
> {code}
> 06:53:52,011 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 56) MSC000001: Failed to start service jboss.persistenceunit."stateful.war#mypc": org.jboss.msc.service.StartException in service jboss.persistenceunit."stateful.war#mypc": org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.spi.CacheImplementor]
>     at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:112) [wildfly-jpa-8.0.0.Alpha2-SNAPSHOT.jar:8.0.0.Alpha2-SNAPSHOT]
>     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_15]
>     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_15]
>     at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_15]
>     at org.jboss.threads.JBossThread.run(JBossThread.java:122) [jboss-threads-2.1.0.Final.jar:2.1.0.Final]
> Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.spi.CacheImplementor]
>     at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:186)
>     at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:150)
>     at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
>     at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:270)
>     at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1816)
>     at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:844)
>     at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:836)
>     at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:368)
>     at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:835)
>     at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:142)
>     at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:214) [wildfly-jpa-8.0.0.Alpha2-SNAPSHOT.jar:8.0.0.Alpha2-SNAPSHOT]
>     at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.access$800(PersistenceUnitServiceImpl.java:59) [wildfly-jpa-8.0.0.Alpha2-SNAPSHOT.jar:8.0.0.Alpha2-SNAPSHOT]
>     at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:108) [wildfly-jpa-8.0.0.Alpha2-SNAPSHOT.jar:8.0.0.Alpha2-SNAPSHOT]
>     ... 4 more
> Caused by: org.hibernate.cache.CacheException: Unable to start region factory
>     at org.hibernate.cache.infinispan.InfinispanRegionFactory.start(InfinispanRegionFactory.java:340)
>     at org.hibernate.internal.CacheImpl.<init>(CacheImpl.java:70)
>     at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:40)
>     at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:35)
>     at org.hibernate.service.internal.SessionFactoryServiceRegistryImpl.initiateService(SessionFactoryServiceRegistryImpl.java:91)
>     at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:176)
>     ... 16 more
> Caused by: java.lang.NullPointerException
>     at org.hibernate.cache.infinispan.InfinispanRegionFactory.applyConfiguration(InfinispanRegionFactory.java:574)
>     at org.hibernate.cache.infinispan.InfinispanRegionFactory.defineGenericDataTypeCacheConfigurations(InfinispanRegionFactory.java:512)
>     at org.hibernate.cache.infinispan.InfinispanRegionFactory.start(InfinispanRegionFactory.java:333)
>     ... 21 more
> {code}
> Complete test run here teamcity.cafe-babe.org/viewLog.html?buildId=5251&tab=buildResultsDiv&buildTypeId=bt27#testNameId7970967843579505173

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the jboss-jira mailing list