gorm-hibernate5 icon indicating copy to clipboard operation
gorm-hibernate5 copied to clipboard

Race condition

Open erichmx opened this issue 7 years ago • 0 comments

I'm having a weird error with a plugin, but I think it is a race condition in HibernateMappingContextConfiguration, long story short, it gives me a NullPointerException on the line 266 ((ServiceRegistryImplementor)serviceRegistry).destroy();

From what I see, the SessionFactoryObserver is set before the serviceRegistry is created therefore leading to a NPE in some cases, and so my app runs some times and other times it flops with NPE. I don't really understand why sessionFactoryImple.Close() is being called, and this may be another problem.


        setSessionFactoryObserver(new SessionFactoryObserver() {
            private static final long serialVersionUID = 1;
            public void sessionFactoryCreated(SessionFactory factory) {}
            public void sessionFactoryClosed(SessionFactory factory) {
                ((ServiceRegistryImplementor)serviceRegistry).destroy();
            }
        });

        StandardServiceRegistryBuilder standardServiceRegistryBuilder = createStandardServiceRegistryBuilder(bootstrapServiceRegistry)
                                                                                    .applySettings(getProperties());

        StandardServiceRegistry serviceRegistry = standardServiceRegistryBuilder.build();
        sessionFactory = super.buildSessionFactory(serviceRegistry);
        this.serviceRegistry = serviceRegistry;

Am I wrong thinking this may produce a race condition?

Here is more detail of issue https://github.com/mathpere/grails-hibernate-search-plugin/issues/33

erichmx avatar Jul 19 '17 21:07 erichmx