Skip to content

Add URI to message of TimeoutException when timeout #1032

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

Closed
wants to merge 1 commit into from
Closed
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
Add URI to message of TimeoutException when timeout
  • Loading branch information
Atry committed Nov 9, 2015
commit 3b5e57af83ff6ecaa938bdc9d0cfed8a2d15ba4d
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public <T> void writeRequest(NettyResponseFuture<T> future, Channel channel) {

// don't bother scheduling timeouts if channel became invalid
if (Channels.isChannelValid(channel))
scheduleTimeouts(future);
scheduleTimeouts(httpRequest, future);

} catch (Exception e) {
LOGGER.error("Can't write request", e);
Expand All @@ -335,7 +335,7 @@ private void configureTransferAdapter(AsyncHandler<?> handler, HttpRequest httpR
TransferCompletionHandler.class.cast(handler).headers(h);
}

private void scheduleTimeouts(NettyResponseFuture<?> nettyResponseFuture) {
private void scheduleTimeouts(HttpRequest httpRequest, NettyResponseFuture<?> nettyResponseFuture) {

nettyResponseFuture.touch();
int requestTimeoutInMs = requestTimeout(config, nettyResponseFuture.getTargetRequest());
Expand All @@ -348,7 +348,7 @@ private void scheduleTimeouts(NettyResponseFuture<?> nettyResponseFuture) {
int readTimeoutValue = config.getReadTimeout();
if (readTimeoutValue != -1 && readTimeoutValue < requestTimeoutInMs) {
// no need to schedule a readTimeout if the requestTimeout happens first
Timeout readTimeout = newTimeout(new ReadTimeoutTimerTask(nettyResponseFuture, this, timeoutsHolder, requestTimeoutInMs, readTimeoutValue), readTimeoutValue);
Timeout readTimeout = newTimeout(new ReadTimeoutTimerTask(nettyResponseFuture, this, timeoutsHolder, requestTimeoutInMs, readTimeoutValue, httpRequest), readTimeoutValue);
timeoutsHolder.readTimeout = readTimeout;
}
nettyResponseFuture.setTimeoutsHolder(timeoutsHolder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
package org.asynchttpclient.netty.timeout;

import static org.asynchttpclient.util.DateUtils.millisTime;

import io.netty.handler.codec.http.HttpRequest;
import io.netty.util.Timeout;

import org.asynchttpclient.netty.NettyResponseFuture;
Expand All @@ -23,15 +25,27 @@ public class ReadTimeoutTimerTask extends TimeoutTimerTask {

private final long readTimeout;
private final long requestTimeoutInstant;
private final HttpRequest httpRequest;

public ReadTimeoutTimerTask(//
NettyResponseFuture<?> nettyResponseFuture,//
NettyRequestSender requestSender,//
TimeoutsHolder timeoutsHolder,//
long requestTimeout,//
long readTimeout) {
this(nettyResponseFuture, requestSender, timeoutsHolder, requestTimeout, readTimeout, null);
}

public ReadTimeoutTimerTask(//
NettyResponseFuture<?> nettyResponseFuture,//
NettyRequestSender requestSender,//
TimeoutsHolder timeoutsHolder,//
long requestTimeout,//
long readTimeout,//
HttpRequest httpRequest) {
super(nettyResponseFuture, requestSender, timeoutsHolder);
this.readTimeout = readTimeout;
this.httpRequest = httpRequest;
requestTimeoutInstant = requestTimeout >= 0 ? nettyResponseFuture.getStart() + requestTimeout : Long.MAX_VALUE;
}

Expand All @@ -52,7 +66,12 @@ public void run(Timeout timeout) throws Exception {

if (durationBeforeCurrentReadTimeout <= 0L) {
// idleConnectTimeout reached
String message = "Read timeout to " + remoteAddress + " of " + readTimeout + " ms";
String message;
if (httpRequest == null) {
message = "Read timeout to " + remoteAddress + " of " + readTimeout + " ms";
} else {
message = "Read timeout to " + httpRequest.getUri() + " of " + readTimeout + " ms";
}
long durationSinceLastTouch = now - nettyResponseFuture.getLastTouch();
expire(message, durationSinceLastTouch);
// cancel request timeout sibling
Expand Down