Skip to content

Commit 178ca7f

Browse files
committed
Add some dev comments
1 parent 6c4712b commit 178ca7f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,14 +315,17 @@ protected final <T> void writeRequest(final Channel channel,
315315
final NettyResponseFuture<T> future,
316316
final HttpRequest nettyRequest) {
317317
try {
318+
/**
319+
* 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.
321+
*/
318322
if (!channel.isOpen() || !channel.isConnected()) {
319323
if (!remotelyClosed(channel, future)) {
320324
abort(future, new ConnectException());
321-
return;
322325
} else {
323326
log.debug("Request {} has been recovered", nettyRequest);
324-
return;
325327
}
328+
return;
326329
}
327330

328331
Body body = null;
@@ -344,7 +347,6 @@ protected final <T> void writeRequest(final Channel channel,
344347
}
345348
}
346349

347-
348350
if (TransferCompletionHandler.class.isAssignableFrom(future.getAsyncHandler().getClass())) {
349351

350352
FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap();
@@ -1629,6 +1631,10 @@ public void operationComplete(ChannelFuture cf) {
16291631
}
16301632
future.touch();
16311633

1634+
/**
1635+
* We need to make sure we aren't in the middle of an authorization process before publishing events
1636+
* as we will re-publish again the same event after the authorization, causing unpredictable behavior.
1637+
*/
16321638
Realm realm = future.getRequest().getRealm() != null ? future.getRequest().getRealm() : NettyAsyncHttpProvider.this.getConfig().getRealm();
16331639
boolean startPublishing = future.isInAuth()
16341640
|| realm == null

0 commit comments

Comments
 (0)