Also check suppressed exceptions when detecting RequestCancelledException
If an exception is thrown finally blocks are still executed. If there
is another exception in the finally block, then the original exception
gets suppressed. To properly detect cancelled requests in this situation
we should inspect suppressed exceptions too. From our logs we know that
this is happening sometimes.
Bug: Google b/151127672
Release-Notes: skip
Change-Id: Ice39dbdec9638de75de32da6973c91421ffac14a
Signed-off-by: Edwin Kempin <ekempin@google.com>
diff --git a/java/com/google/gerrit/server/cancellation/RequestCancelledException.java b/java/com/google/gerrit/server/cancellation/RequestCancelledException.java
index dc01567..9663427 100644
--- a/java/com/google/gerrit/server/cancellation/RequestCancelledException.java
+++ b/java/com/google/gerrit/server/cancellation/RequestCancelledException.java
@@ -15,7 +15,9 @@
package com.google.gerrit.server.cancellation;
import com.google.common.base.Throwables;
+import com.google.common.collect.Streams;
import com.google.gerrit.common.Nullable;
+import java.util.Arrays;
import java.util.Optional;
import org.apache.commons.text.WordUtils;
@@ -28,7 +30,9 @@
* {@link RequestCancelledException} is returned. If not, {@link Optional#empty()} is returned.
*/
public static Optional<RequestCancelledException> getFromCausalChain(Throwable e) {
- return Throwables.getCausalChain(e).stream()
+ return Streams.concat(
+ Throwables.getCausalChain(e).stream(),
+ Throwables.getCausalChain(e).stream().flatMap(t -> Arrays.stream(t.getSuppressed())))
.filter(RequestCancelledException.class::isInstance)
.map(RequestCancelledException.class::cast)
.findFirst();