From ceb4ace118944b04a4997d8e85e3cf19d0aa1fd9 Mon Sep 17 00:00:00 2001 From: Gian Merlino Date: Tue, 14 Jun 2022 13:34:46 -0700 Subject: [PATCH] NettyHttpClient: Replace ReadTimeoutException with our own exception. (#12635) * NettyHttpClient: Replace ReadTimeoutException with our own exception. * Replace exception with same type. * Remove unused import. --- .../druid/java/util/http/client/NettyHttpClient.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/apache/druid/java/util/http/client/NettyHttpClient.java b/core/src/main/java/org/apache/druid/java/util/http/client/NettyHttpClient.java index 25adef45325..3e7376222f3 100644 --- a/core/src/main/java/org/apache/druid/java/util/http/client/NettyHttpClient.java +++ b/core/src/main/java/org/apache/druid/java/util/http/client/NettyHttpClient.java @@ -50,6 +50,7 @@ import org.jboss.netty.handler.codec.http.HttpMethod; import org.jboss.netty.handler.codec.http.HttpRequest; import org.jboss.netty.handler.codec.http.HttpResponse; import org.jboss.netty.handler.codec.http.HttpVersion; +import org.jboss.netty.handler.timeout.ReadTimeoutException; import org.jboss.netty.handler.timeout.ReadTimeoutHandler; import org.jboss.netty.util.Timer; import org.joda.time.Duration; @@ -316,7 +317,14 @@ public class NettyHttpClient extends AbstractHttpClient } } - retVal.setException(event.getCause()); + if (event.getCause() instanceof ReadTimeoutException) { + // ReadTimeoutException thrown by ReadTimeoutHandler is a singleton with a misleading stack trace. + // No point including it: instead, we replace it with a fresh exception. + retVal.setException(new ReadTimeoutException(StringUtils.format("[%s] Read timed out", requestDesc))); + } else { + retVal.setException(event.getCause()); + } + // response is non-null if we received initial chunk and then exception occurs if (response != null) { handler.exceptionCaught(response, event.getCause());