4343import io .netty5 .util .Resource ;
4444import io .netty5 .util .Send ;
4545import io .netty5 .util .concurrent .Future ;
46+ import io .netty5 .util .internal .SilentDispose ;
4647import java .net .URI ;
4748import java .net .URISyntaxException ;
4849import java .time .Instant ;
@@ -242,6 +243,7 @@ private void handleMessage(
242243 }
243244
244245 // check if the response set in the context should actually be transferred to the client
246+ var closeResponse = true ;
245247 if (!context .cancelSendResponse ) {
246248 var response = context .httpServerResponse ;
247249
@@ -271,6 +273,7 @@ private void handleMessage(
271273 HttpUtil .setTransferEncodingChunked (netty , false );
272274 HttpUtil .setContentLength (netty , netty .payload ().readableBytes ());
273275 future = channel .writeAndFlush (netty );
276+ closeResponse = false ; // already done by http content encoder
274277 }
275278
276279 // add the listener that fires the exception if an error occurs during writing of the response
@@ -279,6 +282,11 @@ private void handleMessage(
279282 future .addListener (channel , ChannelFutureListeners .CLOSE );
280283 }
281284 }
285+
286+ if (closeResponse ) {
287+ var response = context .httpServerResponse .httpResponse ;
288+ SilentDispose .tryPropagatingDispose (response );
289+ }
282290 }
283291
284292 private void postToFallbackHandler (@ NonNull NettyHttpServerContext context ) {
0 commit comments