Skip to content

Add URI to message of TimeoutException when timeout #1031

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
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,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 (Throwable t) {
LOGGER.error("Can't write request", t);
Expand Down Expand Up @@ -386,7 +386,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.getRequest());
Expand All @@ -401,7 +401,7 @@ private void scheduleTimeouts(NettyResponseFuture<?> nettyResponseFuture) {
if (readTimeoutValue != -1 && readTimeoutValue < requestTimeoutInMs) {
// no need for a readTimeout that's less than the requestTimeout
Timeout readTimeout = newTimeout(new ReadTimeoutTimerTask(nettyResponseFuture, this, timeoutsHolder,
requestTimeoutInMs, readTimeoutValue), readTimeoutValue);
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,7 @@

import static com.ning.http.util.DateUtils.millisTime;

import org.jboss.netty.handler.codec.http.HttpRequest;
import org.jboss.netty.util.Timeout;

import com.ning.http.client.providers.netty.future.NettyResponseFuture;
Expand All @@ -23,15 +24,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 +65,12 @@ public void run(Timeout timeout) throws Exception {

if (durationBeforeCurrentReadTimeout <= 0L) {
// readTimeout 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