Print out thread dump on strict context check failure (#4664)

* Print out thread dump on strict context check failure

* suppress warning
This commit is contained in:
Lauri Tulmin 2021-11-18 15:42:54 +02:00 committed by GitHub
parent db0d0c350a
commit 31d87162f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 1 deletions

View File

@ -41,7 +41,8 @@ public final class ContextStorageCloser {
// retry close when scope leak was reported.
await()
.ignoreException(AssertionError.class)
.atMost(Duration.ofSeconds(15))
.atMost(Duration.ofSeconds(10))
.pollInterval(Duration.ofSeconds(1))
.until(() -> restorer.runWithRestore(storage));
}
@ -50,6 +51,7 @@ public final class ContextStorageCloser {
private abstract static class ContextRestorer {
abstract void restore();
@SuppressWarnings("SystemOut")
boolean runWithRestore(AutoCloseable target) {
try {
target.close();
@ -57,6 +59,15 @@ public final class ContextStorageCloser {
} catch (Throwable throwable) {
restore();
if (throwable instanceof AssertionError) {
System.err.println();
for (Map.Entry<Thread, StackTraceElement[]> threadEntry :
Thread.getAllStackTraces().entrySet()) {
System.err.println("Thread " + threadEntry.getKey());
for (StackTraceElement stackTraceElement : threadEntry.getValue()) {
System.err.println("\t" + stackTraceElement);
}
System.err.println();
}
throw (AssertionError) throwable;
}
throw new IllegalStateException(throwable);