Skip to content

Commit 75221a0

Browse files
committed
Not proper events order in case of handshake failure, close AsyncHttpClient#841
1 parent 5ab632f commit 75221a0

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/main/java/com/ning/http/client/providers/netty/channel/ChannelManager.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,6 @@ public SslHandler createSslHandler(String peerHost, int peerPort) throws General
399399
SSLEngine sslEngine = sslEngineFactory.newSSLEngine(peerHost, peerPort);
400400
SslHandler sslHandler = handshakeTimeout > 0 ? new SslHandler(sslEngine, getDefaultBufferPool(), false, nettyTimer,
401401
handshakeTimeout) : new SslHandler(sslEngine);
402-
sslHandler.setIssueHandshake(true);
403402
sslHandler.setCloseOnSSLException(true);
404403
return sslHandler;
405404
}

src/main/java/com/ning/http/client/providers/netty/request/NettyConnectListener.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.jboss.netty.channel.Channel;
1919
import org.jboss.netty.channel.ChannelFuture;
2020
import org.jboss.netty.channel.ChannelFutureListener;
21+
import org.jboss.netty.handler.ssl.SslHandler;
2122
import org.slf4j.Logger;
2223
import org.slf4j.LoggerFactory;
2324

@@ -61,10 +62,12 @@ private void abortChannelPreemption(String partition) {
6162
channelManager.abortChannelPreemption(partition);
6263
}
6364

64-
private void writeRequest(Channel channel, String partition) {
65+
private void writeRequest(Channel channel) {
6566

6667
LOGGER.debug("Request using non cached Channel '{}':\n{}\n", channel, future.getNettyRequest().getHttpRequest());
6768

69+
Channels.setAttribute(channel, future);
70+
6871
if (future.isDone()) {
6972
abortChannelPreemption(partition);
7073
return;
@@ -79,8 +82,24 @@ private void writeRequest(Channel channel, String partition) {
7982
}
8083

8184
private void onFutureSuccess(final Channel channel) throws ConnectException {
82-
Channels.setAttribute(channel, future);
83-
writeRequest(channel, partition);
85+
86+
SslHandler sslHandler = channel.getPipeline().get(SslHandler.class);
87+
88+
if (sslHandler != null) {
89+
sslHandler.handshake().addListener(new ChannelFutureListener() {
90+
91+
@Override
92+
public void operationComplete(ChannelFuture future) throws Exception {
93+
if (future.isSuccess())
94+
writeRequest(channel);
95+
else
96+
onFutureFailure(channel, future.getCause());
97+
}
98+
});
99+
100+
} else {
101+
writeRequest(channel);
102+
}
84103
}
85104

86105
private void onFutureFailure(Channel channel, Throwable cause) {

0 commit comments

Comments
 (0)