We're updating the issue view to help you get more done. 

Synchronization during JTA afterCompletion() incompatible with Hibernate-Core

Description

During synchronization Hibernate Core's SessionImpl.close() calls org.hibernate.engine.transaction.internal.TransactionCoordinator.close() which in-turns calls org.hibernate.engine.transaction.internal.TransactionCoordinator.reset(). During the reset the transactionCoordinator calls org.hibernate.engine.transaction.internal.SynchronizationRegistry.clearSynchronizations(). The synchronizations list is emptied and nulled. This removes the BeforeCommitSynchronizationDelegator instance that was registered from org.hibernate.search.backend.impl.EventSourceTransactionContext.registerSynchronization() during the JTA transaction. Clearing the synchronization list causes a ConcurrentModificationException to be thrown from org.hibernate.search.backend.impl.SynchronizationRegistryImpl.notifySynchronizationsAfterTransactionCompletion() because it is iterating the synchronization list and at the start it contains two Synchronization instances in this order (EntityManagerImpl.Synchronization, BeforeCommitSynchronizationDelegator). So, basically the first Synchronization is removing the second Synchronization while in a loop...

ARJUNA016029: SynchronizationImple.afterCompletion - failed for org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization@192e31c with exception
java.util.ConcurrentModificationException
at java.util.LinkedHashMap$LinkedHashIterator.nextEntry(LinkedHashMap.java:373)
at java.util.LinkedHashMap$KeyIterator.next(LinkedHashMap.java:384)
at org.hibernate.engine.transaction.internal.SynchronizationRegistryImpl.notifySynchronizationsAfterTransactionCompletion(SynchronizationRegistryImpl.java:78)
at org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl.sendAfterTransactionCompletionNotifications(TransactionCoordinatorImpl.java:335)
at org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl.afterTransaction(TransactionCoordinatorImpl.java:147)
at org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorImpl.afterCompletion(SynchronizationCallbackCoordinatorImpl.java:126)
at org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization.afterCompletion(RegisteredSynchronization.java:61)
at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.afterCompletion(SynchronizationImple.java:117)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.afterCompletion(TwoPhaseCoordinator.java:403)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:104)
at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:159)
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1162)
at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:119)
at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1010)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120)

Environment

None

Status

Assignee

Sanne Grinovero

Reporter

Eli Colner

Suitable for new contributors

None

Pull Request

None

Feedback Requested

None

Components

Priority

Critical