GeezerVison is showing github.com — Event loop group shutdown with IOUring slow on Java 25 · Issue #16174 · netty/netty
Event loop group shutdown with IOUring slow on Java 25 #16174DescriptionEnvironment: Netty version: 4.2.9.Final
Hi, we hit a problem in an integration test suite that rapidly creates and destroys some netty based test clients, where they preferred IOUring as transport, and they are running on java 25. The tests were running out of resources and on debugging we found that the netty event loop threads were unexpectedly growing throughout our tests and eventually exhausting resources somewhere. In our tests we were closing the EventLoopGroup but not blocking on the shutdown future completing. Changing the clients to use epoll fixed our test issue. Also interesting is that our test suite running on java 21 is not affected.
With some debugging I found that the EventLoopGroups were taking a very long time to be destroyed.
Here's a reproducer demonstrating that there is a difference between how long it takes to shutdown IOUring ELGs on java 21 vs java 25. It appears that it is related to how many ELGs you are trying to destroy in parallel, as well as how many threads you have in each ELG.
https://github.com/robobario/iouring-reproducer/tree/main
There are some details in the reproducer about my environment and a flamegraph attached where the vast majority of the time is spent in jdk.internal.misc.ScopedMemoryAccess.closeScope0(MemorySessionImpl, ScopedMemoryAccess$ScopedAccessError), which was caused by io.netty.channel.uring.IoUringIoHandler.destroy().
Maybe this is related to #15582, another problem with IOUring shutdown taking a long time. ActivitySamBarker commented on Jan 23, 2026 I've reproduced the failure using @robobario code https://github.com/robobario/iouring-reproducer/tree/main
Temurin 25
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running EventLoopGroupShutdownTest
WARNING: A restricted method in java.lang.System has been called
WARNING: java.lang.System::loadLibrary has been called by io.netty.util.internal.NativeLibraryUtil in an unnamed module (file:/home/sam/.m2/repository/io/netty/netty-common/4.2.9.Final/netty-common-4.2.9.Final.jar)
WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module
WARNING: Restricted methods will be blocked in a future release unless native access is enabled
ELG shutdown gracefully in 55921 milliseconds
ELG shutdown gracefully in 39 milliseconds
ELG shutdown gracefully in 853914 milliseconds
ELG shutdown gracefully in 854083 milliseconds
ELG shutdown gracefully in 853996 milliseconds
ELG shutdown gracefully in 46 milliseconds
ELG shutdown gracefully in 45 milliseconds
ELG shutdown gracefully in 42 milliseconds
ELG shutdown gracefully in 83 milliseconds
ELG shutdown gracefully in 392 milliseconds
ELG shutdown gracefully in 495 milliseconds
ELG shutdown gracefully in 512 milliseconds
ELG shutdown gracefully in 420 milliseconds
ELG shutdown gracefully in 291 milliseconds
ELG shutdown gracefully in 508 milliseconds
ELG shutdown gracefully in 4105 milliseconds
ELG shutdown gracefully in 4092 milliseconds
ELG shutdown gracefully in 4182 milliseconds
ELG shutdown gracefully in 585 milliseconds
ELG shutdown gracefully in 2488 milliseconds
ELG shutdown gracefully in 2520 milliseconds
ELG shutdown gracefully in 2531 milliseconds
[ERROR] Tests run: 12, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 920.2 s <<< FAILURE! -- in EventLoopGroupShutdownTest
[ERROR] EventLoopGroupShutdownTest.shutdown(IoHandlerFactory, Class, int, int)[1] -- Time elapsed: 56.40 s <<< FAILURE!
org.opentest4j.AssertionFailedError: took longer than 10 seconds to close all client ELGs ==> expected: <true> but was: <false>
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.AssertTrue.failNotTrue(AssertTrue.java:63)
at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:36)
at org.junit.jupiter.api.Assertions.assertTrue(Assertions.java:214)
at EventLoopGroupShutdownTest.shutdown(EventLoopGroupShutdownTest.java:57)
at java.base/java.lang.reflect.Method.invoke(Method.java:565)
at java.base/java.util.Optional.ifPresent(Optional.java:178)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:186)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:214)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:186)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:186)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:214)
at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:1024)
at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:803)
at java.base/java.util.stream.ReferencePipeline$7$1FlatMap.accept(ReferencePipeline.java:293)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:214)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:214)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:214)
at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:1024)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:570)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:560)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:153)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:176)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:632)
at java.base/java.util.stream.ReferencePipeline$7$1FlatMap.accept(ReferencePipeline.java:293)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1716)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:570)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:560)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:153)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:176)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:632)
at java.base/java.util.stream.ReferencePipeline$7$1FlatMap.accept(ReferencePipeline.java:293)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:214)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:214)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:214)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1716)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:570)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:560)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:153)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:176)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:632)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1604)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1604)
❯ sdk current java
Alias tip: sdkc java
Using java version 25.0.1-tem
❯ java --version
openjdk 25.0.1 2025-10-21 LTS
OpenJDK Runtime Environment Temurin-25.0.1+8 (build 25.0.1+8-LTS)
OpenJDK 64-Bit Server VM Temurin-25.0.1+8 (build 25.0.1+8-LTS, mixed mode, sharing)
Temurin 21
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running EventLoopGroupShutdownTest
ELG shutdown gracefully in 95 milliseconds
ELG shutdown gracefully in 9 milliseconds
ELG shutdown gracefully in 95 milliseconds
ELG shutdown gracefully in 80 milliseconds
ELG shutdown gracefully in 77 milliseconds
ELG shutdown gracefully in 13 milliseconds
ELG shutdown gracefully in 12 milliseconds
ELG shutdown gracefully in 11 milliseconds
ELG shutdown gracefully in 1 milliseconds
ELG shutdown gracefully in 1 milliseconds
ELG shutdown gracefully in 0 milliseconds
ELG shutdown gracefully in 1 milliseconds
ELG shutdown gracefully in 1 milliseconds
ELG shutdown gracefully in 2 milliseconds
ELG shutdown gracefully in 3 milliseconds
ELG shutdown gracefully in 7 milliseconds
ELG shutdown gracefully in 8 milliseconds
ELG shutdown gracefully in 4 milliseconds
ELG shutdown gracefully in 3 milliseconds
ELG shutdown gracefully in 3 milliseconds
ELG shutdown gracefully in 6 milliseconds
ELG shutdown gracefully in 3 milliseconds
[INFO] Tests run: 12, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.225 s -- in EventLoopGroupShutdownTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 12, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.707 s
[INFO] Finished at: 2026-01-23T16:28:56+13:00
[INFO] ------------------------------------------------------------------------
❯ java --version
openjdk 21.0.9 2025-10-21 LTS
OpenJDK Runtime Environment Temurin-21.0.9+10 (build 21.0.9+10-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.9+10 (build 21.0.9+10-LTS, mixed mode, sharing)
Reacted by Robert Young and Francesco Nigro chrisvest commented on Jan 23, 2026 Please paste a run with debug logging enabled.
Also, does it help if you run that app with a --enable-native-access=ALL-UNNAMED argument for the JVM on the command line? Reacted by Francesco Nigro robobario commented on Jan 23, 2026 Thanks @chrisvest . With --enable-native-access=ALL-UNNAMED it behaves in line with 21 (tested with temurin 25 and corretto 25).
java -version
openjdk version "25.0.1" 2025-10-21 LTS
OpenJDK Runtime Environment Temurin-25.0.1+8 (build 25.0.1+8-LTS)
OpenJDK 64-Bit Server VM Temurin-25.0.1+8 (build 25.0.1+8-LTS, mixed mode, sharing)
mvn test
...
[INFO] Running EventLoopGroupShutdownTest
ELG shutdown gracefully in 22 milliseconds
ELG shutdown gracefully in 3 milliseconds
ELG shutdown gracefully in 10 milliseconds
ELG shutdown gracefully in 18 milliseconds
ELG shutdown gracefully in 11 milliseconds
ELG shutdown gracefully in 5 milliseconds
ELG shutdown gracefully in 3 milliseconds
ELG shutdown gracefully in 3 milliseconds
ELG shutdown gracefully in 1 milliseconds
ELG shutdown gracefully in 1 milliseconds
ELG shutdown gracefully in 1 milliseconds
ELG shutdown gracefully in 0 milliseconds
ELG shutdown gracefully in 1 milliseconds
ELG shutdown gracefully in 1 milliseconds
ELG shutdown gracefully in 1 milliseconds
ELG shutdown gracefully in 2 milliseconds
ELG shutdown gracefully in 2 milliseconds
ELG shutdown gracefully in 1 milliseconds
ELG shutdown gracefully in 1 milliseconds
ELG shutdown gracefully in 1 milliseconds
ELG shutdown gracefully in 1 milliseconds
ELG shutdown gracefully in 1 milliseconds
[INFO] Tests run: 12, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.600 s -- in EventLoopGroupShutdownTest
Done by adding:
<configuration>
<argLine>--enable-native-access=ALL-UNNAMED</argLine>
</configuration>
to the surefire config.
Can confirm I can't see anywhere in our project setting this, so looks like a failure to read the manual on our side https://netty.io/wiki/java-24-and-sun.misc.unsafe.html#netty-42-and-unsafe.
Edit: though if I use the the arg line in the wiki --enable-native-access=io.netty.common it doesn't work and I get a warning, Unknown module: io.netty.common specified to --enable-native-access. Looks like other issues cover that.
Ah it won't be on the module path, right, would have to add something else to the surefire config. normanmaurer commented on Jan 25, 2026 That's interesting... @chrisvest do you have time to investigate next week ? franz1981 commented on Jan 25, 2026 The reason could be related memory segments destroyed that wasn't using malloc/fee but the segment handshakes dreamlike-ocean commented on Feb 5, 2026 A successful close of a shared scope always triggers a full handshake: SharedSession.justClose() → ScopedMemoryAccess.closeScope0 → Handshake::execute, which waits for all Java threads to process the handshake, and may inject async exceptions or deoptimize.
IoUringIoHandler.msgHdrMemoryArray has 1024 MsgHdrMemory instances, each allocating 4 CleanableDirectBuffers. On JDK 25, each clean() closes a shared Arena, so shutdown performs 1024 * 4 closeScope0 calls, i.e., excessive handshakes.
Enable native access so Netty can use CleanerJava24Linker (malloc/free) instead of shared Arena close.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.4</version>
<configuration>
<argLine>
--enable-native-access=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
</plugins>
</build>
This enables native access for the unnamed module, allowing CleanerJava24Linker and avoiding shared‑Arena close handshakes.
I have two alternative solutions
1.Add a Buffer.allocateThreadLocalDirectBuffer* API backed by Arena.ofConfined().
allocate and release on the same thread to avoid shared close.
2.Reimplement MsgHdrMemoryArray to allocate one large segment and slice for each MsgHdrMemory.
collapses 4096 shared closes into a single close. normanmaurer commented on Feb 5, 2026 @dreamlike-ocean I think 2) might be the best way to implement it... Would you be willing to do a PR ? dreamlike-ocean commented on Feb 5, 2026
@dreamlike-ocean I think 2) might be the best way to implement it... Would you be willing to do a PR ?
I will do a PR to fix it 😊 Reacted by Norman Maurer and yes开发工程师 Reacted by Norman Maurer and yes开发工程师 dreamlike-ocean commented on Feb 5, 2026
@dreamlike-ocean I think 2) might be the best way to implement it... Would you be willing to do a PR ?
#16234
done!
The PR is complete. Please review added a commit that references this issue on Feb 10, 2026This issue will close once commit 3aeb944 is merged into the '4.2' branch.3aeb944 added a commit that references this issue on Feb 10, 2026This issue will close once commit 0306ded is merged into the '4.2' branch.0306ded added a commit that references this issue on Feb 11, 2026This issue will close once commit ebca4b9 is merged into the '4.2' branch.ebca4b9
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|