GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||
GeezerVison is showing github.com — FlowControlHandler no longer honors setAutoRead(false) made by a downstream handler while dequeuing (regression in 4.2.15) · Issue #16945 · netty/netty Closed DescriptionExpected behaviorWhen a downstream handler calls This is the behavior documented in the class javadoc of * class MyExampleHandler extends ChannelInboundHandlerAdapter { * @Override * public void channelRead(ChannelHandlerContext ctx, Object msg) { * if (msg instanceof HttpRequest) { * ctx.channel().config().setAutoRead(false); * * // The FlowControlHandler will hold any subsequent events that * // were emitted by HttpObjectDecoder until auto reading is turned * // back on or Channel#read() is being called. * } * } * } Up to and including Netty 4.1.135.Final and 4.2.14.Final, this worked because the dequeue loop // 4.1.135.Final / 4.2.14.Final private int dequeue(ChannelHandlerContext ctx, int minConsume) { int consumed = 0; while (queue != null && (consumed < minConsume || config.isAutoRead())) { Object msg = queue.poll(); ... ctx.fireChannelRead(msg); } ... } If Actual behaviorSince 4.2.15.Final (#16837, the 4.2 backport of #15053 "FlowControlHandler: Suppress duplicate // 4.2.15.Final @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ... queue.offer(msg); if (config.isAutoRead()) { dequeueAll(ctx); // maxConsume = -1, unlimited } else if (unsatisfiedReads > 0) { dequeueOne(ctx); ... } } private int dequeue(ChannelHandlerContext ctx, int maxConsume) { int consumed = 0; while (queue != null && (consumed < maxConsume || maxConsume < 0)) { Object msg = queue.poll(); ... ctx.fireChannelRead(msg); } ... } Once The same rewrite has since landed on the 4.1 branch as well (#16912, after 4.1.135.Final was Why this mattersThe per-message auto-read responsiveness is the core value of Concrete real-world impact: Apache Pulsar places Steps to reproduceRun the JUnit test below (e.g. dropped into
The failures are: The scenario: messages accumulate in Minimal yet complete reproducer code (or URL to code)import static org.junit.jupiter.api.Assertions.assertEquals; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.embedded.EmbeddedChannel; import io.netty.handler.flow.FlowControlHandler; import java.util.ArrayList; import java.util.List; import org.junit.jupiter.api.Test; public class FlowControlHandlerAutoReadTest { @Test public void autoReadDisabledDuringChannelReadStopsDelivery() { List<Object> received = new ArrayList<>(); ChannelInboundHandlerAdapter throttlingHandler = new ChannelInboundHandlerAdapter() { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) { received.add(msg); // pause the connection while "processing" each message, // like the example in FlowControlHandler's javadoc ctx.channel().config().setAutoRead(false); } }; EmbeddedChannel channel = new EmbeddedChannel(new FlowControlHandler(), throttlingHandler); // The downstream handler disables auto-read while processing the first message; // messages 2..5 are held in FlowControlHandler's queue (works on all versions). channel.writeInbound("1", "2", "3", "4", "5"); assertEquals(1, received.size()); // Resume: the downstream handler is still over its limit and disables auto-read // again while processing the first released message. // // 4.1.135 / 4.2.14: passes - exactly one more queued message is released; the // dequeue loop observes the renewed setAutoRead(false) and stops. // 4.2.15: fails with received.size() == 5 - dequeueAll() drains the whole // queue, ignoring the auto-read change made by the downstream // handler mid-drain. channel.config().setAutoRead(true); assertEquals(2, received.size()); channel.finishAndReleaseAll(); } } Netty versionRegression introduced in 4.2.15.Final via #16837 (backport of #15053). 4.2.14.Final and JVM version (e.g.
| ||||||||||||
| 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. |