Skip to content

Commit 5963e60

Browse files
committed
Improve logging and do not replay request when cauthException gets invoked as eventualy closeChannel will recover itself from it
1 parent a2cd1d7 commit 5963e60

File tree

3 files changed

+29
-35
lines changed

3 files changed

+29
-35
lines changed

pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
<groupId>ch.qos.logback</groupId>
8181
<artifactId>logback-classic</artifactId>
8282
<version>0.9.26</version>
83-
<scope>test</scope>
8483
</dependency>
8584
<dependency>
8685
<groupId>log4j</groupId>

src/main/java/com/ning/http/client/providers/netty/NettyAsyncHttpProvider.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@
100100
import java.net.InetSocketAddress;
101101
import java.net.MalformedURLException;
102102
import java.net.URI;
103-
import java.net.URISyntaxException;
104103
import java.nio.channels.ClosedChannelException;
105104
import java.nio.channels.FileChannel;
106105
import java.nio.channels.WritableByteChannel;
@@ -749,7 +748,7 @@ private <T> ListenableFuture<T> doConnect(final Request request, final AsyncHand
749748
f.setState(NettyResponseFuture.STATE.POOLED);
750749
f.attachChannel(channel, false);
751750

752-
log.debug("\nUsing cached Channel {}\n for request {}\n", channel, request);
751+
log.debug("\nUsing cached Channel {}\n for request \n{}\n", channel, nettyRequest);
753752
channel.getPipeline().getContext(NettyAsyncHttpProvider.class).setAttachment(f);
754753

755754
try {
@@ -824,7 +823,7 @@ private <T> ListenableFuture<T> doConnect(final Request request, final AsyncHand
824823
channelFuture.addListener(c);
825824
}
826825

827-
log.debug("\n\nNon cached Request {}\n with channel {}\n", request, channel);
826+
log.debug("\nNon cached request \n{}\n\nusing Channel \n{}\n", c.future().getNettyRequest(), channelFuture.getChannel());
828827

829828
if (!c.future().isCancelled() || !c.future().isDone()) {
830829
openChannels.add(channelFuture.getChannel());
@@ -1343,7 +1342,7 @@ protected boolean remotelyClosed(Channel channel, NettyResponseFuture<?> future)
13431342
}
13441343

13451344
if (future == null || future.cannotBeReplay()) {
1346-
log.debug("Unable to replay request {}\n associated with future {}\n", future == null ? "null" : future.getNettyRequest(), future);
1345+
log.debug("Unable to recover request {}\n associated with future {}\n", future == null ? "null" : future.getNettyRequest(), future);
13471346
return false;
13481347
}
13491348

@@ -1400,7 +1399,7 @@ public Object call() throws Exception {
14001399
}
14011400

14021401
private boolean markChannelNotReadable(final ChannelHandlerContext ctx) {
1403-
// Catch any unexpected exception when marking the channel.
1402+
// Catch any unexpected exception when marking the channel.
14041403
ctx.setAttachment(new DiscardEvent());
14051404
return true;
14061405
}
@@ -1432,6 +1431,13 @@ public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
14321431
Throwable cause = e.getCause();
14331432
NettyResponseFuture<?> future = null;
14341433

1434+
if (log.isDebugEnabled()) {
1435+
log.debug("Exception Caught: {} Attachment was {}",
1436+
cause != null ? cause.getMessage() : "unavailable cause",
1437+
ctx.getAttachment());
1438+
log.debug(cause.getMessage(), cause);
1439+
}
1440+
14351441
try {
14361442

14371443
if (cause != null && ClosedChannelException.class.isAssignableFrom(cause.getClass())) {
@@ -1454,10 +1460,8 @@ public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
14541460
}
14551461

14561462
if (abortOnReadCloseException(cause) || abortOnWriteCloseException(cause)) {
1457-
log.debug("Trying to recover from dead Channel: {}\n request {}", channel, future.getNettyRequest());
1458-
if (remotelyClosed(channel, future)) {
1459-
return;
1460-
}
1463+
log.debug("Trying to recover from dead Channel: {}", channel);
1464+
return;
14611465
}
14621466
} else if (ctx.getAttachment() instanceof AsyncCallable) {
14631467
future = ((AsyncCallable) ctx.getAttachment()).future();
@@ -1473,13 +1477,6 @@ public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
14731477
log.error(t.getMessage(), t);
14741478
}
14751479
}
1476-
1477-
if (log.isDebugEnabled()) {
1478-
log.error("Exception Caught: {} Attachment was {}",
1479-
cause != null ? cause.getMessage() : "unavailable cause",
1480-
ctx.getAttachment());
1481-
log.error(cause.getMessage(), cause);
1482-
}
14831480
closeChannel(ctx);
14841481
ctx.sendUpstream(e);
14851482
}

src/main/java/com/ning/http/client/providers/netty/NettyResponseFuture.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package com.ning.http.client.providers.netty;
1717

1818
import com.ning.http.client.AsyncHandler;
19-
import com.ning.http.client.ListenableFuture;
2019
import com.ning.http.client.Request;
2120
import com.ning.http.client.listenable.AbstractListenableFuture;
2221
import org.jboss.netty.channel.Channel;
@@ -422,23 +421,22 @@ public boolean cannotBeReplay() {
422421
@Override
423422
public String toString() {
424423
return "NettyResponseFuture{" +
425-
"latch=" + latch +
426-
", isDone=" + isDone +
427-
", isCancelled=" + isCancelled +
428-
", asyncHandler=" + asyncHandler +
429-
", responseTimeoutInMs=" + responseTimeoutInMs +
430-
", request=" + request +
431-
", nettyRequest=" + nettyRequest +
432-
", content=" + content +
433-
", uri=" + uri +
434-
", keepAlive=" + keepAlive +
435-
", httpResponse=" + httpResponse +
436-
", exEx=" + exEx +
437-
", redirectCount=" + redirectCount +
438-
", reaperFuture=" + reaperFuture +
439-
", inAuth=" + inAuth +
440-
", statusReceived=" + statusReceived +
441-
", touch=" + touch +
424+
"currentRetry=" + currentRetry +
425+
",\nisDone=" + isDone +
426+
",\nisCancelled=" + isCancelled +
427+
",\nasyncHandler=" + asyncHandler +
428+
",\nresponseTimeoutInMs=" + responseTimeoutInMs +
429+
",\nnettyRequest=" + nettyRequest +
430+
",\ncontent=" + content +
431+
",\nuri=" + uri +
432+
",\nkeepAlive=" + keepAlive +
433+
",\nhttpResponse=" + httpResponse +
434+
",\nexEx=" + exEx +
435+
",\nredirectCount=" + redirectCount +
436+
",\nreaperFuture=" + reaperFuture +
437+
",\ninAuth=" + inAuth +
438+
",\nstatusReceived=" + statusReceived +
439+
",\ntouch=" + touch +
442440
'}';
443441
}
444442

0 commit comments

Comments
 (0)