diff --git a/api/src/org/labkey/api/data/DbScope.java b/api/src/org/labkey/api/data/DbScope.java index 50af17eb9c9..6e9663bf496 100644 --- a/api/src/org/labkey/api/data/DbScope.java +++ b/api/src/org/labkey/api/data/DbScope.java @@ -50,7 +50,6 @@ import org.labkey.api.util.GUID; import org.labkey.api.util.LoggerWriter; import org.labkey.api.util.MemTracker; -import org.labkey.api.util.Pair; import org.labkey.api.util.ResultSetUtil; import org.labkey.api.util.SimpleLoggerWriter; import org.labkey.api.util.SkipMothershipLogging; @@ -3271,9 +3270,8 @@ public void testLockTimeout() { ReentrantLock lock1 = new ReentrantLock(); ReentrantLock lock2 = new ReentrantLock(); - Pair throwables = attemptToDeadlock(lock1, lock2, (x) -> ((TransactionImpl)x).setLockTimeout(5, TimeUnit.SECONDS)); + attemptToDeadlock(lock1, lock2, (x) -> ((TransactionImpl)x).setLockTimeout(5, TimeUnit.SECONDS), DeadlockPreventingException.class); - assertTrue(throwables.first instanceof DeadlockPreventingException || throwables.second instanceof DeadlockPreventingException); assertFalse("Lock 1 is still locked", lock1.isLocked()); assertFalse("Lock 2 is still locked", lock2.isLocked()); } @@ -3394,18 +3392,13 @@ public void testServerRowLock() Lock lockUser = new ServerPrimaryKeyLock(true, CoreSchema.getInstance().getTableInfoUsersData(), user.getUserId()); Lock lockHome = new ServerPrimaryKeyLock(true, CoreSchema.getInstance().getTableInfoContainers(), ContainerManager.getHomeContainer().getId()); - Pair throwables = attemptToDeadlock(lockUser, lockHome, (x) -> {}); - - assertTrue("Unexpected exceptions: " + throwables.first + "\n" + throwables.second, throwables.first instanceof PessimisticLockingFailureException || throwables.second instanceof PessimisticLockingFailureException ); + attemptToDeadlock(lockUser, lockHome, (x) -> {}, PessimisticLockingFailureException.class); } - /** - * @return foreground and background thread exceptions - */ - private Pair attemptToDeadlock(Lock lock1, Lock lock2, @NotNull Consumer transactionModifier) + private void attemptToDeadlock(Lock lock1, Lock lock2, @NotNull Consumer transactionModifier, Class expectedException) { final Object notifier = new Object(); - final Pair result = new Pair<>(null, null); + final List result = new ArrayList<>(); // let's try to intentionally cause a deadlock Thread bkg = new Thread(() -> { @@ -3431,7 +3424,7 @@ private Pair attemptToDeadlock(Lock lock1, Lock lock2, @No } catch (Throwable x) { - result.second = x; + result.add(x); } } }); @@ -3465,7 +3458,7 @@ private Pair attemptToDeadlock(Lock lock1, Lock lock2, @No } catch (Throwable x) { - result.first = x; + result.add(x); } finally { @@ -3479,7 +3472,13 @@ private Pair attemptToDeadlock(Lock lock1, Lock lock2, @No } } } - return result; + + assertFalse("No exceptions from attempted deadlock.", result.isEmpty()); + result.stream().filter(t -> !expectedException.isAssignableFrom(t.getClass())) + .findAny().ifPresent(t -> { + throw new AssertionError("Wrong error from deadlock. expected: <" + + expectedException.getSimpleName() + ">, but was <" + t.getClass().getSimpleName() + ">", t); + }); } @Test diff --git a/api/src/org/labkey/api/util/DebugInfoDumper.java b/api/src/org/labkey/api/util/DebugInfoDumper.java index c252ab34bb2..0aa02445f66 100644 --- a/api/src/org/labkey/api/util/DebugInfoDumper.java +++ b/api/src/org/labkey/api/util/DebugInfoDumper.java @@ -412,8 +412,22 @@ public static synchronized void dumpThreads(LoggerWriter logWriter) // Schema won't exist on SQLServer if (schema != null) { - writeTable(logWriter, schema, BasePostgreSqlDialect.POSTGRES_STAT_ACTIVITY_TABLE_NAME, "Postgres activity"); - writeTable(logWriter, schema, BasePostgreSqlDialect.POSTGRES_LOCKS_TABLE_NAME, "Postgres locks"); + try + { + writeTable(logWriter, schema, BasePostgreSqlDialect.POSTGRES_LOCKS_TABLE_NAME, "Postgres locks"); + } + catch (RuntimeException e) + { + logWriter.debug("Failed to write Postgres locks table:" + e); + } + try + { + writeTable(logWriter, schema, BasePostgreSqlDialect.POSTGRES_STAT_ACTIVITY_TABLE_NAME, "Postgres activity"); + } + catch (RuntimeException e) + { + logWriter.debug("Failed to write Postgres activity table:" + e); + } } } @@ -434,7 +448,7 @@ private static void writeTable(LoggerWriter logWriter, UserSchema schema, String PrintWriter printWriter = new PrintWriter(stringWriter); writer.write(printWriter); printWriter.flush(); - logWriter.debug("\n" + stringWriter.toString()); + logWriter.debug("\n" + stringWriter); } catch (IOException e) {