Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2020-02-18 18:54:15 +0000
committerEike Stepper2020-02-18 18:54:15 +0000
commit4c5cc26ab9266fcd3b0fcbb3d620b162f5234b1d (patch)
tree9a63601cedc4f4cb0e19f913af3ba82c28de462d
parent353f9270d3ff7a5081819a7d77cb5e90e950cc22 (diff)
downloadcdo-4c5cc26ab9266fcd3b0fcbb3d620b162f5234b1d.tar.gz
cdo-4c5cc26ab9266fcd3b0fcbb3d620b162f5234b1d.tar.xz
cdo-4c5cc26ab9266fcd3b0fcbb3d620b162f5234b1d.zip
[560280] Possible deadlock during the session invalidation
https://bugs.eclipse.org/bugs/show_bug.cgi?id=560280
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_560280_Test.java121
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java25
2 files changed, 137 insertions, 9 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_560280_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_560280_Test.java
new file mode 100644
index 0000000000..763276ae05
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_560280_Test.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2008-2012, 2015 Eike Stepper (Loehne, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.internal.net4j.CDONet4jSessionConfigurationImpl;
+import org.eclipse.emf.cdo.internal.net4j.CDONet4jSessionImpl;
+import org.eclipse.emf.cdo.net4j.CDONet4jSessionConfiguration;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.tests.config.IRepositoryConfig;
+import org.eclipse.emf.cdo.tests.config.impl.SessionConfig;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CommitException;
+
+import org.eclipse.emf.spi.cdo.InternalCDOSession;
+import org.eclipse.emf.spi.cdo.InternalCDOView;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * Bug 560280 - Possible deadlock during the session invalidation.
+ *
+ * @author Eike Stepper
+ */
+public class Bugzilla_560280_Test extends AbstractCDOTest
+{
+ public void testDeadlockBetweenInvalidationAndCommit() throws Exception
+ {
+ CDOSession session1 = openSession();
+ CDOTransaction transaction1 = session1.openTransaction();
+ CDOResource resource1 = transaction1.createResource(getResourcePath("resource1"));
+ transaction1.commit();
+
+ AtomicReference<CDOTransaction> transactionUnderTest = new AtomicReference<>();
+ AtomicBoolean controlUpdatePermissions = new AtomicBoolean();
+ CountDownLatch reachedUpdatePermissions = new CountDownLatch(1);
+ CountDownLatch allowUpdatePermissions = new CountDownLatch(1);
+
+ CDONet4jSessionConfiguration configuration = new CDONet4jSessionConfigurationImpl()
+ {
+ @Override
+ public InternalCDOSession createSession()
+ {
+ return new CDONet4jSessionImpl()
+ {
+ @Override
+ public InternalCDOView[] getViews()
+ {
+ if (controlUpdatePermissions.get())
+ {
+ reachedUpdatePermissions.countDown();
+ await(allowUpdatePermissions);
+
+ transactionUnderTest.get().syncExec(() -> {
+ // Just take the view lock.
+ });
+ }
+
+ return super.getViews();
+ }
+ };
+ }
+ };
+
+ CDONet4jSessionConfiguration template = (CDONet4jSessionConfiguration)((SessionConfig)getSessionConfig())
+ .createSessionConfiguration(IRepositoryConfig.REPOSITORY_NAME);
+ configuration.setConnector(template.getConnector());
+ configuration.setRepositoryName(template.getRepositoryName());
+ configuration.setRevisionManager(template.getRevisionManager());
+
+ getTestProperties().put(SessionConfig.PROP_TEST_SESSION_CONFIGURATION, configuration);
+
+ CDOSession sessionUnderTest = openSession();
+ transactionUnderTest.set(sessionUnderTest.openTransaction());
+ CDOResource resourceUnderTest = transactionUnderTest.get().createResource(getResourcePath("resourceUnderTest"));
+
+ /*
+ * Test Logic:
+ */
+
+ controlUpdatePermissions.set(true);
+
+ resource1.getContents().add(getModel1Factory().createCompany());
+ transaction1.commit();
+
+ // Execute transactionUndertTest.commit() on a separate thread so that the deadlock doesn't freeze the test suite.
+ new PollingTimeOuter()
+ {
+ @Override
+ protected boolean successful()
+ {
+ await(reachedUpdatePermissions);
+ allowUpdatePermissions.countDown();
+
+ try
+ {
+ resourceUnderTest.getContents().add(getModel1Factory().createCompany());
+ transactionUnderTest.get().commit();
+ }
+ catch (CommitException ex)
+ {
+ // This is really not expected now.
+ ex.printStackTrace();
+ }
+
+ return true;
+ }
+ }.assertNoTimeOut();
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java
index 2c67eb1db8..3f45246014 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java
@@ -1648,24 +1648,31 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
private CDOCommitInfo commitSynced(IProgressMonitor progressMonitor) throws DanglingIntegrityException, CommitException
{
+ try
+ {
+ checkActive();
+ }
+ catch (Exception ex)
+ {
+ throw new CommitException(ex);
+ }
+
+ InternalCDOSession session = getSession();
+ commitToken = (CommitToken)session.startLocalCommit();
+
synchronized (getViewMonitor())
{
lockView();
try
{
- InternalCDOSession session = getSession();
+ if (hasConflict())
+ {
+ throw new LocalCommitConflictException(Messages.getString("CDOTransactionImpl.2")); //$NON-NLS-1$
+ }
try
{
- checkActive();
- if (hasConflict())
- {
- throw new LocalCommitConflictException(Messages.getString("CDOTransactionImpl.2")); //$NON-NLS-1$
- }
-
- commitToken = (CommitToken)session.startLocalCommit();
-
CDOTransactionStrategy transactionStrategy = getTransactionStrategy();
CDOCommitInfo info = transactionStrategy.commit(this, progressMonitor);
if (info != null)

Back to the top