Skip to content

Commit

Permalink
Merge pull request wildfly#11983 from scottmarlow/WFLY-11563_Persiste…
Browse files Browse the repository at this point in the history
…nceUnitServiceImplNPE

WFLY-11563 Race condition in PersistenceUnitServiceImpl when the service is being stopped
  • Loading branch information
kabir authored Jan 9, 2019
2 parents 6dfee69 + 31ac8dc commit 99bfad8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,23 @@ public Void run() {
}
try {
if (entityManagerFactory != null) {
WritableServiceBasedNamingStore.pushOwner(deploymentUnitServiceName);
try {
if (entityManagerFactory.isOpen()) {
entityManagerFactory.close();
// protect against race condition reported by WFLY-11563
synchronized (this) {
if (entityManagerFactory != null) {
WritableServiceBasedNamingStore.pushOwner(deploymentUnitServiceName);
try {
if (entityManagerFactory.isOpen()) {
entityManagerFactory.close();
}
} catch (Throwable t) {
ROOT_LOGGER.failedToStopPUService(t, pu.getScopedPersistenceUnitName());
} finally {
entityManagerFactory = null;
pu.setTempClassLoaderFactory(null);
WritableServiceBasedNamingStore.popOwner();
persistenceUnitRegistry.remove(getScopedPersistenceUnitName());
}
}
} catch (Throwable t) {
ROOT_LOGGER.failedToStopPUService(t, pu.getScopedPersistenceUnitName());
} finally {
entityManagerFactory = null;
pu.setTempClassLoaderFactory(null);
WritableServiceBasedNamingStore.popOwner();
persistenceUnitRegistry.remove(getScopedPersistenceUnitName());
}
}
} finally {
Expand All @@ -271,8 +276,12 @@ public Void run() {
}
}
if (proxyBeanManager != null) {
proxyBeanManager.setDelegate(null);
proxyBeanManager = null;
synchronized (this) {
if (proxyBeanManager != null) {
proxyBeanManager.setDelegate(null);
proxyBeanManager = null;
}
}
}
context.complete();
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public class TestEntityManagerFactory implements InvocationHandler {
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

invocations.add(method.getName());
if (method.getName().equals("isOpen")) {
return false;
}
return null;

}
Expand Down

0 comments on commit 99bfad8

Please sign in to comment.