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 — Respect max messages per read in LocalServerChannel (#17255) by normanmaurer · Pull Request #17269 · netty/netty

Respect max messages per read in LocalServerChannel (#17255) #17269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
normanmaurer merged 2 commits into 4.1 from read_41
Aug 12, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

Respect max messages per read in LocalServerChannel (#17255) #17269

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
719b3e0
Respect max messages per read in LocalServerChannel (#17255)
Gimini-3 Aug 12, 2026
3b97ae1
Fix
normanmaurer Aug 12, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

1 change: 1 addition & 0 deletions 1 transport/src/main/java/io/netty/channel/local/LocalServerChannel.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ private void readInbound() {
if (m == null) {
break;
}
handle.incMessagesRead(1);
pipeline.fireChannelRead(m);
} while (handle.continueReading());
handle.readComplete();
Expand Down
90 changes: 90 additions & 0 deletions 90 transport/src/test/java/io/netty/channel/local/LocalChannelTest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.netty.buffer.Unpooled;
import io.netty.channel.AbstractChannel;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFactory;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
Expand All @@ -32,6 +33,7 @@
import io.netty.channel.DefaultMaxMessagesRecvByteBufAllocator;
import io.netty.channel.EventLoop;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.ServerChannel;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.SingleThreadEventLoop;
import io.netty.util.ReferenceCountUtil;
Expand All @@ -48,8 +50,12 @@
import java.net.ConnectException;
import java.nio.channels.AlreadyConnectedException;
import java.nio.channels.ClosedChannelException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

Expand Down Expand Up @@ -1217,6 +1223,90 @@ protected void initChannel(Channel ch) {
}
}

@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testServerMaxMessagesPerReadRespectedWithQueuedConnections() throws Exception {
final int maxMessagesPerRead = 2;
final int connections = 5;
final CountDownLatch queuedConnections = new CountDownLatch(connections);
final BlockingQueue<Integer> messagesPerReadComplete = new LinkedBlockingQueue<Integer>();
final List<ChannelFuture> connectFutures = new ArrayList<ChannelFuture>();

Bootstrap cb = new Bootstrap();
ServerBootstrap sb = new ServerBootstrap();

cb.group(sharedGroup)
.channel(LocalChannel.class)
.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) {
// NOOP
}
});

sb.group(sharedGroup)
.channelFactory(new ChannelFactory<ServerChannel>() {
@Override
public ServerChannel newChannel() {
return new LocalServerChannel() {
@Override
protected LocalChannel newLocalChannel(LocalChannel peer) {
LocalChannel child = super.newLocalChannel(peer);
queuedConnections.countDown();
return child;
}
};
}
})
.option(ChannelOption.AUTO_READ, false)
.option(ChannelOption.MAX_MESSAGES_PER_READ, maxMessagesPerRead)
.handler(new ChannelInboundHandlerAdapter() {
private int messagesRead;

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
messagesRead++;
ctx.fireChannelRead(msg);
}

@Override
public void channelReadComplete(ChannelHandlerContext ctx) {
messagesPerReadComplete.add(messagesRead);
messagesRead = 0;
ctx.fireChannelReadComplete();
}
})
.childHandler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) {
// NOOP
}
});

Channel sc = null;
try {
sc = sb.bind(TEST_ADDRESS).sync().channel();
for (int i = 0; i < connections; i++) {
connectFutures.add(cb.connect(TEST_ADDRESS));
}

assertTrue(queuedConnections.await(5, SECONDS));

sc.config().setAutoRead(true);
assertEquals(maxMessagesPerRead, messagesPerReadComplete.take());
assertEquals(maxMessagesPerRead, messagesPerReadComplete.take());
assertEquals(connections - 2 * maxMessagesPerRead, messagesPerReadComplete.take());
for (ChannelFuture connectFuture : connectFutures) {
connectFuture.sync();
}
} finally {
for (ChannelFuture connectFuture : connectFutures) {
closeChannel(connectFuture.channel());
}
closeChannel(sc);
}
}

private static final class ChannelReadHandler extends ChannelInboundHandlerAdapter {

private final CountDownLatch latch;
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
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.