GeezerVison is showing github.com — Potential memory leak after upgrading from 4.2.10 to 4.2.11 · Issue #16606 · netty/netty
Potential memory leak after upgrading from 4.2.10 to 4.2.11 #16606DescriptionWe are seeing OOM kills in Kubernetes after upgrading from SpringBoot from 4.0.4 to 4.0.5, which transitively bumps Netty from 4.2.10 to 4.2.11.
Forcing all io.netty packages (except the tcnative) back to 4.2.10 seems to solve the issue.
Our metrics show considerably higher memory usage already half an hour after Pod restart (i.e., it only takes half an hour to require more memory than what previous was needed once steady state was reached after a couple of hours), which continues to rise until it eventually restarts due to an OOMKill from Kubernetes as the memory limit is reached.
Our stack only uses Netty as an HTTP client, we use Jetty as HTTP server for SpringBoot. We do heavy polling (1 call every 500ms).
Not sure what exactly causes the issue, will report back if and when I find something new.
If anybody is looking for anything specifically, happy to provide additional information. Just not sure what to look for. Reacted by Benedikt Halser and Tomas Kiziela Activitychanged the title [-]Potential memory leak after upgrading from 4.2.10 to 4.2.12[/-] [+]Potential memory leak after upgrading from 4.2.10 to 4.2.11[/+] on Apr 8, 2026j-be commented on Apr 8, 2026 Was able to reproduce the issue on 4.2.11. Updated title and description. slandelle commented on Apr 8, 2026 @j-be Have you collected and analyzed heap dumps? franz1981 commented on Apr 8, 2026 Ca you run:
- With paranoid leak detection settings
- If not conclusive, async profiler with men leak profiling or -e mprotect
?
Or you can bisect the release commits? j-be commented on Apr 9, 2026 @slandelle Not yet.
@franz1981 I have paranoid leak detection on, but I don't see anything in the logs for now. Maybe because of the workaround (see below)
Turns out: it seems like it only affects our K8s deployments. So it is a bit hard to get a hold of a dump.
So it may be related to explicitly how Netty is used inside the AWS S3 SDK and how AWS S3 behaves (local deployments use a different object storage), or it has something to do with our K8s setup, e.g., Istio.
I also asked Claude what it thinks, and it came up with the idea to try and set -Dio.netty.ignoreExpensiveClean=true as a workaround and it seems to indeed either prevent the leak entirely, or at least heavily slow down the memory usage ramp up. It's too soon to tell which of the 2 it is, I'll need to see how it evolves over the weekend. But after running for an hour our metrics definitely show an improvement with total memory usage being considerably lower than without it.
In any case, Claude now thinks #16443 is the primary culprit, and I'll just leave its conclusion here uncommented, as I am sure any of you has more idea what it meams by that then I do 😅
What the ignoreExpensiveClean=true Flag Tells Us
It confirms PR #16443 is the primary culprit, not PR #16306. The flag directly toggles that change, so the root cause is now clear.
What actually changed in 4.2.11
Before 4.2.11: When an UnpooledDirectByteBuf's refcount hit 0, its native (off-heap) memory was freed immediately and synchronously via a Java MemorySegment shared arena close. Memory returned to the OS right away.
After 4.2.11 (PR #16443): Native memory cleanup was delegated to the JVM garbage collector via PhantomReference/Cleaner. The ByteBuf object must first be GC'd, then the cleaner runs, then the memory is freed. Three async hops.
Why this leaks on Kubernetes + Istio but not locally
It's not a true leak — the memory would eventually be freed. But:
- Kubernetes pods have strict memory limits (e.g. 512MB). The JVM heap only uses part of that. Direct memory sits outside the heap, so heap GC doesn't create pressure to collect it.
- Your polling rate (every 500ms via HTTP/2 over Istio) creates unpooled direct buffers faster than the GC reference queue processes their cleaners.
- Locally you have no memory ceiling to hit before GC catches up naturally.
The result: direct memory grows unboundedly until Kubernetes OOM-kills the pod — which looks exactly like a leak.
What ignoreExpensiveClean=true does
It restores the pre-4.2.11 synchronous cleanup path, making deallocation eager and deterministic again, at the cost of the shared arena close overhead that PR #16443 was trying to avoid. franz1981 commented on Apr 9, 2026 @claude is right -> -Dio.netty.ignoreExpensiveClean=true
It indeed is very BAD on containers with little parallelism and which have OOM killer ready to hit. @chrisvest ^^
@cescoffier too normanmaurer commented on Apr 9, 2026 So does this mean you are using the UnpooledByteBufAllocator @j-be ? franz1981 commented on Apr 9, 2026 @normanmaurer depends.
In Netty 4.2 the chunk reuse queue capacity depends by the number of cores. With container with small cores we end up creating and freeing many chunks, hitting this, too.
IMHO we still have work to do (my fault, I am behind in this work...sorry) for container friendly allocators ^^ chrisvest commented on Apr 9, 2026 @j-be can you share some OutOfMemoryError stack traces? The "ignore expensive clean" only affects direct buffers, not heap memory.
Oh wait, you're seeing oomkills, not OOMEs? Then it tracks, but you are also missing or have misconfigured a native memory limit. j-be commented on Apr 9, 2026 @chrisvest Jep, "exit code 137 because of OOMKilled" by Kubernetes, no OutOfMemoryError (at least none we can see).
Please note, that my knowledge on Java memory limits is limited. And I am not sure how much of our options I am allowed to share.
But from what I can tell, the only memory limits we set are -XX:InitialRAMPercentage=35 and -XX:MaxRAMPercentage=35. That is because the JSONs we fetch are large compared to what we have on heap.
What would you recommend to add here? cmcclung-ANGENG commented on Apr 21, 2026 I can add a bit here
Json parsing can hit the heap that way
There's a few things that can help there
- Avoid always converting to DTOs etc. Instead stream or to tree view from byte[] for what you want, (reusing memory if it makes sense).
- Switch to something like protobuf, there are better alt if its truly big json.
franz1981 commented on Apr 23, 2026 j-be commented on Apr 23, 2026 @franz1981 Currently running Netty 4.2.12 with -Dio.netty.ignoreExpensiveClean=true and everything seems to work just fine 😄 normanmaurer commented on Apr 30, 2026 franz1981 commented on Apr 30, 2026 Tbh @normanmaurer I would prefer it to be switched back..as it was. But I don't remember by heart why was changed - deferring free is bad, but the handshake of memory segments too. Just two different failure modes, and OOM looks very unappealing although is more specific of containers Steror commented on Oct 30, 2026 FYI, this has affected multiple of our apps migrated to Spring Boot 4. Pods run on light containers which default to SerialGC and this GC is unable to keep up with memory growth from netty. Effectively, this results in a memory leak and a 137/OOMKilled.
What worked for us: Switching to G1 GC eliminates the problem. Graphs went from constantly increasing to flat as Kansas. I have not measured impact on performance. Graphs show same average response times, though 99 percentiles may have changed.
I have not evaluated the option to revert this change with flag, but I guess that's another possibility.
-Dio.netty.ignoreExpensiveClean=true
I suspect more people will find this thread as people onboard to SB4. franz1981 commented on Oct 30, 2026 good point @Steror In quarkus I have moved to pass all the proper JVM arguments to default to using cleaner 24 which call into malloc/free instead, exactly for this reason.
G1 is a good solution as it is "garbage first" if it can prompty run cleaners, it would do it, saving OOM, but still, it's deferred.
I strongly suggest to do as we've done with Quarkus 🙏 chrisvest commented on Oct 30, 2026 franz1981 commented on Oct 30, 2026 franz1981 commented on Nov 18, 2026
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|