@@ -50,10 +50,11 @@ State getState() {
5050 return state ;
5151 }
5252
53- @ Override
54- public void channelActive (ChannelHandlerContext ctx ) throws Exception {
55- autoRead = GatedAutoRead .newGate (ctx .channel ());
56- super .channelActive (ctx );
53+ GatedAutoRead .Gate autoRead (ChannelHandlerContext ctx ) {
54+ if (autoRead == null ) {
55+ autoRead = GatedAutoRead .newGate (ctx .channel ());
56+ }
57+ return autoRead ;
5758 }
5859
5960 @ SuppressWarnings ("fallthrough" )
@@ -68,7 +69,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
6869 pending .add (ReferenceCountUtil .retain (httpObject ));
6970 requestStart (ctx );
7071 assert state == QUEUEING_DATA ;
71- assert autoRead .get () == false ;
72+ assert autoRead ( ctx ) .get () == false ;
7273 break ;
7374 case QUEUEING_DATA :
7475 pending .add (ReferenceCountUtil .retain (httpObject ));
@@ -90,7 +91,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
9091 case DROPPING_DATA_PERMANENTLY :
9192 assert pending .isEmpty ();
9293 ReferenceCountUtil .release (httpObject ); // consume without enqueuing
93- autoRead .set (false );
94+ autoRead ( ctx ) .set (false );
9495 break ;
9596 }
9697 }
@@ -113,7 +114,7 @@ private void requestStart(ChannelHandlerContext ctx) {
113114 }
114115
115116 state = QUEUEING_DATA ;
116- autoRead .set (false );
117+ autoRead ( ctx ) .set (false );
117118
118119 if (httpRequest == null ) {
119120 // this looks like a malformed request and will forward without validation
@@ -156,10 +157,10 @@ public void onFailure(Exception e) {
156157 private void forwardFullRequest (ChannelHandlerContext ctx ) {
157158 Transports .assertDefaultThreadContext (threadContext );
158159 assert ctx .channel ().eventLoop ().inEventLoop ();
159- assert autoRead .get () == false ;
160+ assert autoRead ( ctx ) .get () == false ;
160161 assert state == QUEUEING_DATA ;
161162
162- autoRead .set (true );
163+ autoRead ( ctx ) .set (true );
163164 boolean fullRequestForwarded = forwardData (ctx , pending );
164165
165166 assert fullRequestForwarded || pending .isEmpty ();
@@ -176,7 +177,7 @@ private void forwardFullRequest(ChannelHandlerContext ctx) {
176177 private void forwardRequestWithDecoderExceptionAndNoContent (ChannelHandlerContext ctx , Exception e ) {
177178 Transports .assertDefaultThreadContext (threadContext );
178179 assert ctx .channel ().eventLoop ().inEventLoop ();
179- assert autoRead .get () == false ;
180+ assert autoRead ( ctx ) .get () == false ;
180181 assert state == QUEUEING_DATA ;
181182
182183 HttpObject messageToForward = pending .getFirst ();
@@ -187,7 +188,7 @@ private void forwardRequestWithDecoderExceptionAndNoContent(ChannelHandlerContex
187188 }
188189 messageToForward .setDecoderResult (DecoderResult .failure (e ));
189190
190- autoRead .set (true );
191+ autoRead ( ctx ) .set (true );
191192 ctx .fireChannelRead (messageToForward );
192193
193194 assert fullRequestDropped || pending .isEmpty ();
0 commit comments