Skip to content

Commit 1229c6f

Browse files
committed
Rely on Netty's closeChannel to replay request instead of directly from the code. This may cause regression in some application in case the closeChannel is not called, but that would be a bug in Netty
1 parent 178ca7f commit 1229c6f

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

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

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,9 @@ protected final <T> void writeRequest(final Channel channel,
317317
try {
318318
/**
319319
* If the channel is dead because it was pooled and the remote server decided to close it,
320-
* we need to try to recover in order to prevent failing a valid request.
320+
* we just let it go and the closeChannel do it's work.
321321
*/
322322
if (!channel.isOpen() || !channel.isConnected()) {
323-
if (!remotelyClosed(channel, future)) {
324-
abort(future, new ConnectException());
325-
} else {
326-
log.debug("Request {} has been recovered", nettyRequest);
327-
}
328323
return;
329324
}
330325

@@ -366,12 +361,12 @@ protected final <T> void writeRequest(final Channel channel,
366361
channel.write(nettyRequest).addListener(new ProgressListener(true, future.getAsyncHandler(), future));
367362
} catch (Throwable cause) {
368363
log.debug(cause.getMessage(), cause);
369-
370-
if (future.provider().remotelyClosed(channel, future)) {
371-
return;
372-
} else {
373-
future.abort(cause);
364+
try {
365+
channel.close();
366+
} catch (RuntimeException ex) {
367+
log.debug(ex.getMessage(), ex);
374368
}
369+
return;
375370
}
376371
}
377372

@@ -426,10 +421,11 @@ public void operationComplete(ChannelFuture cf) {
426421
}
427422
}
428423
} catch (Throwable ioe) {
429-
if (future.provider().remotelyClosed(channel, future)) {
430-
return;
424+
try {
425+
channel.close();
426+
} catch (RuntimeException ex) {
427+
log.debug(ex.getMessage(), ex);
431428
}
432-
abort(future, ioe);
433429
}
434430

435431
try {
@@ -866,7 +862,7 @@ private void finishChannel(final ChannelHandlerContext ctx) {
866862
try {
867863
ctx.getChannel().close();
868864
} catch (Throwable t) {
869-
log.error("error closing a connection", t);
865+
log.debug("Error closing a connection", t);
870866
}
871867
openChannels.remove(ctx.getChannel());
872868
}
@@ -1604,11 +1600,12 @@ public void operationComplete(ChannelFuture cf) {
16041600

16051601
if (IllegalStateException.class.isAssignableFrom(cause.getClass())) {
16061602
log.debug(cause.getMessage(), cause);
1607-
if (future.provider().remotelyClosed(cf.getChannel(), future)) {
1608-
return;
1609-
} else {
1610-
future.abort(cause);
1603+
try {
1604+
cf.getChannel().close();
1605+
} catch (RuntimeException ex) {
1606+
log.debug(ex.getMessage(), ex);
16111607
}
1608+
return;
16121609
}
16131610

16141611
if (ClosedChannelException.class.isAssignableFrom(cause.getClass())
@@ -1619,11 +1616,12 @@ public void operationComplete(ChannelFuture cf) {
16191616
log.debug(cf.getCause() == null ? "" : cf.getCause().getMessage(), cf.getCause());
16201617
}
16211618

1622-
if (future.provider().remotelyClosed(cf.getChannel(), future)) {
1623-
return;
1624-
} else {
1625-
future.abort(cause);
1619+
try {
1620+
cf.getChannel().close();
1621+
} catch (RuntimeException ex) {
1622+
log.debug(ex.getMessage(), ex);
16261623
}
1624+
return;
16271625
} else {
16281626
future.abort(cause);
16291627
}

0 commit comments

Comments
 (0)