netty: fix server keepalive not initialized bug

fixes #2982
This commit is contained in:
ZHANG Dapeng 2017-05-12 09:05:21 -07:00 committed by GitHub
parent 870dd50eb2
commit 28ad3ba335
2 changed files with 2 additions and 12 deletions

View File

@ -334,6 +334,7 @@ class NettyServerHandler extends AbstractNettyHandler {
if (keepAliveTimeInNanos != SERVER_KEEPALIVE_TIME_NANOS_DISABLED) { if (keepAliveTimeInNanos != SERVER_KEEPALIVE_TIME_NANOS_DISABLED) {
keepAliveManager = new KeepAliveManager(new KeepAlivePinger(ctx), ctx.executor(), keepAliveManager = new KeepAliveManager(new KeepAlivePinger(ctx), ctx.executor(),
keepAliveTimeInNanos, keepAliveTimeoutInNanos, true /* keepAliveDuringTransportIdle */); keepAliveTimeInNanos, keepAliveTimeoutInNanos, true /* keepAliveDuringTransportIdle */);
keepAliveManager.onTransportStarted();
} }
super.handlerAdded(ctx); super.handlerAdded(ctx);
} }
@ -441,9 +442,6 @@ class NettyServerHandler extends AbstractNettyHandler {
@Override @Override
public void handleProtocolNegotiationCompleted(Attributes attrs) { public void handleProtocolNegotiationCompleted(Attributes attrs) {
attributes = transportListener.transportReady(attrs); attributes = transportListener.transportReady(attrs);
if (keepAliveManager != null) {
keepAliveManager.onTransportStarted();
}
} }
@VisibleForTesting @VisibleForTesting
@ -706,7 +704,7 @@ class NettyServerHandler extends AbstractNettyHandler {
logger.log(Level.FINE, String.format("Window: %d", logger.log(Level.FINE, String.format("Window: %d",
decoder().flowController().initialWindowSize(connection().connectionStream()))); decoder().flowController().initialWindowSize(connection().connectionStream())));
} }
} else { } else if (!KEEPALIVE_PING_BUF.equals(data)) {
logger.warning("Received unexpected ping ack. No ping outstanding"); logger.warning("Received unexpected ping ack. No ping outstanding");
} }
} }

View File

@ -398,14 +398,6 @@ public class NettyServerHandlerTest extends NettyHandlerTestBase<NettyServerHand
stream = streamCaptor.getValue(); stream = streamCaptor.getValue();
} }
@Test
public void keepAliveManagerStarted() throws Exception {
manualSetUp();
verify(spyKeepAliveManager).onTransportStarted();
verify(spyKeepAliveManager, never()).onDataReceived();
verify(spyKeepAliveManager, never()).onTransportTermination();
}
@Test @Test
public void keepAliveManagerOnDataReceived_headersRead() throws Exception { public void keepAliveManagerOnDataReceived_headersRead() throws Exception {
manualSetUp(); manualSetUp();