Skip to content

Commit

Permalink
Revert "Preserve the caller's stacktrace for blocking API (#2420)" (#…
Browse files Browse the repository at this point in the history
…2488)

This reverts commit 8b41bf4.

Motivation: 

There are cases when Netty's DNS resolver may put an exception into the cache and return it multiple times. In this case, we keep adding suppressed exceptions to the same instance and it leads to a memory leak and increased logging output.
Let's revert this feature before the upcoming release and revisit later when we figure out the approach for Netty/ST DNS resolver.
  • Loading branch information
idelpivnitskiy committed Jan 24, 2023
1 parent 0e54e33 commit a251047
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import static io.servicetalk.utils.internal.ThrowableUtils.throwException;
import static io.servicetalk.utils.internal.PlatformDependent.throwException;

/**
* Common utility functions to unwrap {@link ExecutionException} from async operations.
Expand Down Expand Up @@ -50,7 +50,7 @@ public static <T> T futureGetCancelOnInterrupt(Future<T> future) throws Exceptio
future.cancel(false);
throw e;
} catch (ExecutionException e) {
return throwException(unwrapExecutionException(e));
return throwException(executionExceptionCause(e));
}
}

Expand All @@ -69,7 +69,7 @@ public static <T> T blockingInvocation(Single<T> source) throws Exception {
try {
return source.toFuture().get();
} catch (final ExecutionException e) {
return throwException(unwrapExecutionException(e));
return throwException(executionExceptionCause(e));
}
}

Expand All @@ -86,31 +86,11 @@ public static void blockingInvocation(Completable source) throws Exception {
try {
source.toFuture().get();
} catch (final ExecutionException e) {
throwException(unwrapExecutionException(e));
throwException(executionExceptionCause(e));
}
}

private static Throwable unwrapExecutionException(ExecutionException ee) {
final Throwable cause = ee.getCause();
if (cause == null) {
return ee;
}
cause.addSuppressed(new SuppressedExecutionException(ee));
return cause;
}

private static final class SuppressedExecutionException extends ExecutionException {
private static final long serialVersionUID = 2001711259056665126L;

SuppressedExecutionException(final ExecutionException original) {
super("Blocking operation terminated with an error");
setStackTrace(original.getStackTrace());
}

@Override
public synchronized Throwable fillInStackTrace() {
// We inherit the stack-trace from the original ExecutionException
return this;
}
private static Throwable executionExceptionCause(ExecutionException original) {
return (original.getCause() != null) ? original.getCause() : original;
}
}

This file was deleted.

0 comments on commit a251047

Please sign in to comment.