netty: Fix client keepalive initialization (again)

d116cc9 fixed the NPE, but the initialization of the manager happened
_after_ newHandler() was called, so a null manager was passed to the
handler.

Fixes #2828
This commit is contained in:
Eric Anderson 2017-03-31 17:21:33 -07:00 committed by GitHub
parent c4bbe66506
commit f9eb545df0
1 changed files with 11 additions and 11 deletions

View File

@ -55,6 +55,7 @@ import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoop;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.http2.StreamBufferingEncoder.Http2ChannelClosedException;
@ -165,14 +166,21 @@ class NettyClientTransport implements ConnectionClientTransport {
public Runnable start(Listener transportListener) {
lifecycleManager = new ClientTransportLifecycleManager(
Preconditions.checkNotNull(transportListener, "listener"));
EventLoop eventLoop = group.next();
if (enableKeepAlive) {
keepAliveManager = new KeepAliveManager(
new ClientKeepAlivePinger(this), eventLoop, keepAliveDelayNanos, keepAliveTimeoutNanos,
false);
}
handler = newHandler();
handler = NettyClientHandler.newHandler(lifecycleManager, keepAliveManager, flowControlWindow,
maxHeaderListSize, Ticker.systemTicker());
HandlerSettings.setAutoWindow(handler);
negotiationHandler = negotiator.newHandler(handler);
Bootstrap b = new Bootstrap();
b.group(group);
b.group(eventLoop);
b.channel(channelType);
if (NioSocketChannel.class.isAssignableFrom(channelType)) {
b.option(SO_KEEPALIVE, true);
@ -231,10 +239,7 @@ class NettyClientTransport implements ConnectionClientTransport {
}
});
if (enableKeepAlive) {
keepAliveManager = new KeepAliveManager(
new ClientKeepAlivePinger(this), channel.eventLoop(), keepAliveDelayNanos,
keepAliveTimeoutNanos, false);
if (keepAliveManager != null) {
keepAliveManager.onTransportStarted();
}
@ -307,9 +312,4 @@ class NettyClientTransport implements ConnectionClientTransport {
}
return Utils.statusFromThrowable(t);
}
private NettyClientHandler newHandler() {
return NettyClientHandler.newHandler(lifecycleManager, keepAliveManager, flowControlWindow,
maxHeaderListSize, Ticker.systemTicker());
}
}