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 — 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 #16606

New issue
Copy link
New issue
Copy link
Closed
Closed
Potential memory leak after upgrading from 4.2.10 to 4.2.11#16606
Copy link

Description

@j-be
j-be
opened on Apr 7, 2026
Issue body actions

We 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

Activity

  1. j-be
    changed 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, 2026
  2. j-be commented on Apr 8, 2026

    @j-be
    j-be
    on Apr 8, 2026
    Author
    More actions

    Was able to reproduce the issue on 4.2.11. Updated title and description.

  3. slandelle commented on Apr 8, 2026

    @slandelle
    slandelle
    on Apr 8, 2026
    Contributor
    More actions

    @j-be Have you collected and analyzed heap dumps?

  4. franz1981 commented on Apr 8, 2026

    @franz1981
    franz1981
    on Apr 8, 2026
    Contributor
    More actions

    Ca you run:

    1. With paranoid leak detection settings
    2. If not conclusive, async profiler with men leak profiling or -e mprotect

    ?
    Or you can bisect the release commits?

  5. j-be commented on Apr 9, 2026

    @j-be
    j-be
    on Apr 9, 2026
    Author
    More actions

    @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.

  6. franz1981 commented on Apr 9, 2026

    @franz1981
    franz1981
    on Apr 9, 2026
    Contributor
    More actions

    @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

  7. normanmaurer commented on Apr 9, 2026

    @normanmaurer
    normanmaurer
    on Apr 9, 2026
    Member
    More actions

    So does this mean you are using the UnpooledByteBufAllocator @j-be ?

  8. franz1981 commented on Apr 9, 2026

    @franz1981
    franz1981
    on Apr 9, 2026
    Contributor
    More actions

    @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 ^^

  9. chrisvest commented on Apr 9, 2026

    @chrisvest
    chrisvest
    on Apr 9, 2026
    Member
    More actions

    @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.

  10. j-be commented on Apr 9, 2026

    @j-be
    j-be
    on Apr 9, 2026
    Author
    More actions

    @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?

  11. cmcclung-ANGENG commented on Apr 21, 2026

    @cmcclung-ANGENG
    cmcclung-ANGENG
    on Apr 21, 2026
    More actions

    I can add a bit here

    Json parsing can hit the heap that way

    There's a few things that can help there

    1. Avoid always converting to DTOs etc. Instead stream or to tree view from byte[] for what you want, (reusing memory if it makes sense).
    2. Switch to something like protobuf, there are better alt if its truly big json.
  12. franz1981 commented on Apr 23, 2026

    @franz1981
    franz1981
    on Apr 23, 2026
    Contributor
    More actions

    Any news @j-be ?

  13. j-be commented on Apr 23, 2026

    @j-be
    j-be
    on Apr 23, 2026
    Author
    More actions

    @franz1981 Currently running Netty 4.2.12 with -Dio.netty.ignoreExpensiveClean=true and everything seems to work just fine 😄

  14. normanmaurer commented on Apr 30, 2026

    @normanmaurer
    normanmaurer
    on Apr 30, 2026
    Member
    More actions

    Maybe we should just document this ? @franz1981 @chrisvest

  15. franz1981 commented on Apr 30, 2026

    @franz1981
    franz1981
    on Apr 30, 2026
    Contributor
    More actions

    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

  16. Steror commented on Oct 30, 2026

    @Steror
    Steror
    on Oct 30, 2026
    More actions

    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.

  17. franz1981 commented on Oct 30, 2026

    @franz1981
    franz1981
    on Oct 30, 2026
    Contributor
    More actions

    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 🙏

    Reacted by Tomas Kiziela
  18. chrisvest commented on Oct 30, 2026

    @chrisvest
    chrisvest
    on Oct 30, 2026
    Member
    More actions

    @franz1981 Should we add a "recommended settings" section to https://github.com/netty/netty/wiki/Java-24-and-sun.misc.Unsafe modeled on what quarkus does?

  19. franz1981 commented on Oct 30, 2026

    @franz1981
    franz1981
    on Oct 30, 2026
    Contributor
    More actions

    Good point @chrisvest I happily take care of it 🙏

  20. franz1981 commented on Nov 18, 2026

    @franz1981
    franz1981
    on Nov 18, 2026
    Contributor
    More actions

    @chrisvest added: https://github.com/netty/netty/wiki/Java-24-and-sun.misc.Unsafe#recommended-settings-for-netty-42-on-java-25
    TL;DR on Java 25+ run with --enable-native-access=ALL-UNNAMED (or io.netty.common on the module path); if that's not possible, -Dio.netty.ignoreExpensiveClean=true.

  21. franz1981
    closed this as completedon Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      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.