GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — FlowControlHandler and HttpContentDecompressor do not play nicely together · Issue #15053 · netty/netty

FlowControlHandler and HttpContentDecompressor do not play nicely together #15053

New issue
Copy link
New issue
Copy link
Open
Open
FlowControlHandler and HttpContentDecompressor do not play nicely together#15053
Copy link

Description

@DaveCTurner
DaveCTurner
opened on Apr 21, 2025
Issue body actions

The following test fails, which indicates behaviour that is surprising to me and I suspect might be a bug:

index d9f5cd5b8d..f8edf63a29 100644
--- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentDecompressorTest.java
+++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpContentDecompressorTest.java
@@ -20,6 +20,7 @@ import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.ChannelInboundHandlerAdapter;
 import io.netty.channel.ChannelOutboundHandlerAdapter;
 import io.netty.channel.embedded.EmbeddedChannel;
+import io.netty.handler.flow.FlowControlHandler;
 import org.junit.jupiter.api.Test;

 import java.util.concurrent.atomic.AtomicInteger;
@@ -70,4 +71,33 @@ public class HttpContentDecompressorTest {
         assertEquals(2, readCalled.get());
         assertFalse(channel.finishAndReleaseAll());
     }
+
+    @Test
+    public void testFlowController() {
+        final AtomicInteger messagesEmitted = new AtomicInteger();
+        final EmbeddedChannel channel = new EmbeddedChannel(
+                new FlowControlHandler(),
+                new HttpContentDecompressor(),
+                new ChannelInboundHandlerAdapter() {
+                    @Override
+                    public void channelRead(ChannelHandlerContext ctx, Object msg) {
+                        messagesEmitted.incrementAndGet();
+                    }
+                });
+
+        channel.config().setAutoRead(false);
+
+        final HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
+        response.headers().set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
+
+        assertFalse(channel.writeInbound(response));
+        assertFalse(channel.writeInbound(new DefaultHttpContent(Unpooled.buffer(1))));
+        assertFalse(channel.writeInbound(new DefaultHttpContent(Unpooled.buffer(1))));
+
+        assertEquals(1, messagesEmitted.get());
+        channel.read();
+        assertEquals(2, messagesEmitted.get());
+        channel.read();
+        assertEquals(3, messagesEmitted.get());
+    }
 }

Specifically, with autoread disabled and a FlowControlHandler in place I would expect the pipeline to emit exactly one message per read() but in fact today it emits all three messages at once:

org.opentest4j.AssertionFailedError: 
Expected :1
Actual   :3
<Click to see difference>

	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:150)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:145)
	at org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:527)
	at io.netty.handler.codec.http.HttpContentDecompressorTest.testFlowController(HttpContentDecompressorTest.java:97)
...

This is happening because the FlowControlHandler fabricates its own READ COMPLETE messages when it empties its queue, but also passes through the READ COMPLETE message from upstream when its internal queue is empty, so the HttpContentDecompressor sees two READ COMPLETE events after processing the first READ. The first such event sets HttpContentDecoder#needRead to true and then the second of them triggers another ctx.read().

Unfortunately I'm not sure whether the problem is that FlowControlHandler emits two READ COMPLETE events in a row without any intervening READ, or if this is expected but HttpContentDecoder should be able to handle those events without triggering another ctx.read(), or indeed if this overall behaviour is expected and I'm just holding it wrong somehow.

Activity

  1. DaveCTurner commented on May 28, 2025

    @DaveCTurner
    DaveCTurner
    on May 28, 2025
    Author
    More actions

    Cross-posted at https://stackoverflow.com/questions/79641971/

  2. schiemon
    added 3 commits that reference this issue on May 28, 2026

    FlowControlHandler: Fix channelReadComplete behaviour

    991bb85

    FlowControlHandler: Fix channelReadComplete behaviour

    0dc0880

    FlowControlHandler: Fix channelReadComplete behaviour

    25ca14c
  3. normanmaurer
    added a commit that references this issue on Jun 1, 2026

    FlowControlHandler: Suppress duplicate channelReadComplete after drai…

    79fc9a4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.