From fe1583c9b42ddf53c11f87daa9cd5c0a99a174b6 Mon Sep 17 00:00:00 2001 From: ZHANG Dapeng Date: Wed, 23 Aug 2017 13:38:05 -0700 Subject: [PATCH] netty: fix transport spuriously in notInUse state Previously, if two streams are added (but not active yet), then the transport is changed into inUse; after that, if one of them gets active and then closed and removed, then the transport will be changed into and staying at notInUse, although the other stream could later be active. --- .../io/grpc/netty/NettyClientHandler.java | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/netty/src/main/java/io/grpc/netty/NettyClientHandler.java b/netty/src/main/java/io/grpc/netty/NettyClientHandler.java index 9eeda18c3c..afef5f2686 100644 --- a/netty/src/main/java/io/grpc/netty/NettyClientHandler.java +++ b/netty/src/main/java/io/grpc/netty/NettyClientHandler.java @@ -184,30 +184,28 @@ class NettyClientHandler extends AbstractNettyHandler { } } - @Override - public void onStreamAdded(Http2Stream stream) { - NettyClientHandler.this.lifecycleManager.notifyInUse(true); - } - - @Override - public void onStreamRemoved(Http2Stream stream) { - if (connection().numActiveStreams() == 0) { - NettyClientHandler.this.lifecycleManager.notifyInUse(false); - } - } - @Override public void onStreamActive(Http2Stream stream) { - if (NettyClientHandler.this.keepAliveManager != null - && connection().numActiveStreams() == 1) { + if (connection().numActiveStreams() != 1) { + return; + } + + NettyClientHandler.this.lifecycleManager.notifyInUse(true); + + if (NettyClientHandler.this.keepAliveManager != null) { NettyClientHandler.this.keepAliveManager.onTransportActive(); } } @Override public void onStreamClosed(Http2Stream stream) { - if (NettyClientHandler.this.keepAliveManager != null - && connection().numActiveStreams() == 0) { + if (connection().numActiveStreams() != 0) { + return; + } + + NettyClientHandler.this.lifecycleManager.notifyInUse(false); + + if (NettyClientHandler.this.keepAliveManager != null) { NettyClientHandler.this.keepAliveManager.onTransportIdle(); } }