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 — Limit the number of queued tasks in NioEventLoopTest.testTaskRemovalO… · netty/netty@9ac8aa3

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • transport/src/test/java/io/netty/channel/nio
    • NioEventLoopTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎transport/src/test/java/io/netty/channel/nio/NioEventLoopTest.java‎

Copy file name to clipboardExpand all lines: transport/src/test/java/io/netty/channel/nio/NioEventLoopTest.java
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.netty.channel.socket.nio.NioServerSocketChannel;
2626
import io.netty.channel.socket.nio.NioSocketChannel;
2727
import io.netty.util.concurrent.Future;
28+
import io.netty.util.concurrent.SingleThreadEventExecutor;
2829
import org.junit.jupiter.api.Test;
2930
import org.junit.jupiter.api.Timeout;
3031

@@ -145,6 +146,8 @@ protected void handle(SocketChannel channel, SelectionKey key) {
145146
}
146147
}
147148

149+
private static final int MAX_PENDING_TASKS = 1024;
150+
148151
@SuppressWarnings("deprecation")
149152
@Test
150153
public void testTaskRemovalOnShutdownThrowsNoUnsupportedOperationException() throws Exception {
@@ -157,12 +160,19 @@ public void testTaskRemovalOnShutdownThrowsNoUnsupportedOperationException() thr
157160
for (int i = 0; i < 250; i++) {
158161
EventLoopGroup group = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory());
159162
final EventLoop loop = group.next();
163+
final SingleThreadEventExecutor executor = (SingleThreadEventExecutor) loop;
160164

161165
Thread t = new Thread(() -> {
162166
try {
163167
for (;;) {
164168
loop.execute(task);
165169
loopStarted.set(true);
170+
// Don't let the queue grow without bounds if the producer is faster than the event loop,
171+
// otherwise we may run into an OutOfMemoryError. Keep it non-empty so we still race with
172+
// the task removal on shutdown.
173+
while (executor.pendingTasks() > MAX_PENDING_TASKS && !executor.isShuttingDown()) {
174+
Thread.yield();
175+
}
166176
}
167177
} catch (Throwable cause) {
168178
error.set(cause);

0 commit comments

Comments
0 (0)
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.