diff --git a/core/src/main/java/com/linecorp/armeria/internal/client/DefaultClientRequestContext.java b/core/src/main/java/com/linecorp/armeria/internal/client/DefaultClientRequestContext.java index 63b8478839c..11cbdefd4eb 100644 --- a/core/src/main/java/com/linecorp/armeria/internal/client/DefaultClientRequestContext.java +++ b/core/src/main/java/com/linecorp/armeria/internal/client/DefaultClientRequestContext.java @@ -525,7 +525,6 @@ private DefaultClientRequestContext(DefaultClientRequestContext ctx, log.startRequest(); responseCancellationScheduler = CancellationScheduler.of(TimeUnit.MILLISECONDS.toNanos(ctx.responseTimeoutMillis())); - updateEventLoop(ctx.eventLoop().withoutContext()); writeTimeoutMillis = ctx.writeTimeoutMillis(); maxResponseLength = ctx.maxResponseLength(); @@ -541,7 +540,7 @@ private DefaultClientRequestContext(DefaultClientRequestContext ctx, // We don't need to acquire an EventLoop for the initial attempt because it's already acquired by // the root context. if (endpoint == null || ctx.endpoint() == endpoint && ctx.log.children().isEmpty()) { - eventLoop = ctx.eventLoop().withoutContext(); + updateEventLoop(ctx.eventLoop().withoutContext()); } else { acquireEventLoop(endpoint); } diff --git a/core/src/main/java/com/linecorp/armeria/internal/common/DefaultCancellationScheduler.java b/core/src/main/java/com/linecorp/armeria/internal/common/DefaultCancellationScheduler.java index 6faa444ada5..953a7195f15 100644 --- a/core/src/main/java/com/linecorp/armeria/internal/common/DefaultCancellationScheduler.java +++ b/core/src/main/java/com/linecorp/armeria/internal/common/DefaultCancellationScheduler.java @@ -32,6 +32,8 @@ import com.linecorp.armeria.common.annotation.Nullable; import com.linecorp.armeria.common.util.TimeoutMode; import com.linecorp.armeria.common.util.UnmodifiableFuture; +import com.linecorp.armeria.server.HttpResponseException; +import com.linecorp.armeria.server.HttpStatusException; import com.linecorp.armeria.server.RequestTimeoutException; import io.netty.util.concurrent.EventExecutor; @@ -355,7 +357,7 @@ public void finishNow(@Nullable Throwable cause) { } if (state == State.INIT) { state = State.FINISHED; - this.cause = getThrowable(server, cause); + this.cause = mapThrowable(server, cause); ((CancellationFuture) whenCancelled()).doComplete(cause); } else if (isInitialized()) { if (eventLoop.inEventLoop()) { @@ -527,7 +529,7 @@ private void invokeTask(@Nullable Throwable cause) { return; } - cause = getThrowable(server, cause); + cause = mapThrowable(server, cause); // Set FINISHING to preclude executing other timeout operations from the callbacks of `whenCancelling()` state = State.FINISHING; @@ -545,14 +547,18 @@ private void invokeTask(@Nullable Throwable cause) { ((CancellationFuture) whenCancelled()).doComplete(cause); } - private static Throwable getThrowable(boolean server, @Nullable Throwable cause) { - if (cause != null) { - return cause; + private static Throwable mapThrowable(boolean server, @Nullable Throwable cause) { + if (cause instanceof HttpStatusException || cause instanceof HttpResponseException) { + // Log the requestCause only when an Http{Status,Response}Exception was created with a cause. + cause = cause.getCause(); } - if (server) { - cause = RequestTimeoutException.get(); - } else { - cause = ResponseTimeoutException.get(); + + if (cause == null) { + if (server) { + cause = RequestTimeoutException.get(); + } else { + cause = ResponseTimeoutException.get(); + } } return cause; }