Skip to content

Wrap ReadTimeoutException and WriteTimeoutException in ResponseHandler #828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private URI endpoint() {
}

private void handleFailure(Supplier<String> msg, Throwable cause) {
log.error(msg.get(), cause);
log.debug(msg.get(), cause);
cause = decorateException(cause);
context.handler().onError(cause);
executeFuture.completeExceptionally(cause);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.HttpUtil;
import io.netty.handler.codec.http.LastHttpContent;
import io.netty.handler.timeout.ReadTimeoutException;
import io.netty.handler.timeout.WriteTimeoutException;
import io.netty.util.AttributeKey;
import java.io.IOException;
import java.nio.ByteBuffer;
Expand Down Expand Up @@ -115,9 +117,10 @@ private static void finalizeRequest(RequestContext requestContext, ChannelHandle
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
RequestContext requestContext = ctx.channel().attr(REQUEST_CONTEXT_KEY).get();
log.error("Exception processing request: {}", requestContext.executeRequest().request(), cause);
requestContext.handler().onError(cause);
executeFuture(ctx).completeExceptionally(cause);
log.debug("Exception processing request: {}", requestContext.executeRequest().request(), cause);
Throwable throwable = wrapException(cause);
requestContext.handler().onError(throwable);
executeFuture(ctx).completeExceptionally(throwable);
runAndLogError("Could not release channel back to the pool", () -> closeAndRelease(ctx));
}

Expand Down Expand Up @@ -355,4 +358,14 @@ protected void channelRead0(ChannelHandlerContext ctx, HttpObject obj) throws Ex
ctx.pipeline().remove(this);
}
}

private Throwable wrapException(Throwable originalCause) {
if (originalCause instanceof ReadTimeoutException) {
return new IOException("Read timed out", originalCause);
} else if (originalCause instanceof WriteTimeoutException) {
return new IOException("Write timed out", originalCause);
}

return originalCause;
}
}