File tree Expand file tree Collapse file tree
netty/src/main/java/io/grpc/netty Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -123,13 +123,6 @@ public void start(ServerListener serverListener) throws IOException {
123123 b .childHandler (new ChannelInitializer <Channel >() {
124124 @ Override
125125 public void initChannel (Channel ch ) throws Exception {
126- eventLoopReferenceCounter .retain ();
127- ch .closeFuture ().addListener (new ChannelFutureListener () {
128- @ Override
129- public void operationComplete (ChannelFuture future ) {
130- eventLoopReferenceCounter .release ();
131- }
132- });
133126 NettyServerTransport transport = new NettyServerTransport (ch , protocolNegotiator ,
134127 maxStreamsPerConnection , flowControlWindow , maxMessageSize , maxHeaderListSize );
135128 ServerTransportListener transportListener ;
@@ -140,10 +133,18 @@ public void operationComplete(ChannelFuture future) {
140133 ch .close ();
141134 return ;
142135 }
143-
136+ // `channel` shutdown can race with `ch` initialization, so this is only safe to increment
137+ // inside the lock.
138+ eventLoopReferenceCounter .retain ();
144139 transportListener = listener .transportCreated (transport );
145140 }
146141 transport .start (transportListener );
142+ ch .closeFuture ().addListener (new ChannelFutureListener () {
143+ @ Override
144+ public void operationComplete (ChannelFuture future ) {
145+ eventLoopReferenceCounter .release ();
146+ }
147+ });
147148 }
148149 });
149150 // Bind and start to accept incoming connections.
You can’t perform that action at this time.
0 commit comments