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 — Direct pool OOM again with netty 4.2.16 · Issue #17107 · netty/netty

Direct pool OOM again with netty 4.2.16 #17107

New issue
Copy link
New issue
Copy link
Closed
Closed
Direct pool OOM again with netty 4.2.16#17107
Copy link

Description

@topEngineerRay
topEngineerRay
opened on Jul 17, 2026
Issue body actions

With netty upgrade to 4.2.16 we got the JVM direct pool OOM issue again , same as here: #15850

error log:
but response failed with cause: reactor.netty.ReactorNetty$InternalNettyException: java.lang.OutOfMemoryError: Cannot reserve 139264 bytes of direct buffer memory (allocated: 268421167, limit: 268435456)

Activity

Next
  1. franz1981 commented on Jul 17, 2026

    @franz1981
    franz1981
    on Jul 17, 2026
    Contributor
    More actions

    Without more details is not easy to help...

  2. He-Pin commented on Jul 17, 2026

    @He-Pin
    He-Pin
    on Jul 17, 2026
    Contributor
    More actions

    @topEngineerRay better with a reproducer

    Reacted by Francesco Nigro
  3. topEngineerRay commented on Jul 17, 2026

    @topEngineerRay
    topEngineerRay
    on Jul 17, 2026
    Author
    More actions

    The service use netty for http call to other service, it also has quite a lot kafka listener/consumer. When the service upgrade to 4.2.16 the direct memory increase immediately after service started and processing some http requests.

    Image

    Its a complex business application and can not share, I will see if I can reproduce with a sample service.

    Reacted by He-Pin(kerr)
  4. topEngineerRay commented on Jul 17, 2026

    @topEngineerRay
    topEngineerRay
    on Jul 17, 2026
    Author
    More actions

    After downgrade netty version to 4.2.12 the memory back to normal, we apply this as a hot fix,as this would cause serious error for business.

  5. topEngineerRay commented on Jul 17, 2026

    @topEngineerRay
    topEngineerRay
    on Jul 17, 2026
    Author
    More actions

    @franz1981 @He-Pin check this repo: https://github.com/topEngineerRay/netty-oom-repo
    and run it with the command in the readme, in my local it will reproduce the OOM error:

    Netty: 4.2.16.Final
    Threads=32 bufSize=1024KB hold=16 iters=5000
    Expecting OutOfMemoryError on direct memory...
    OOM: Cannot reserve 8388608 bytes of direct buffer memory (allocated: 262144001, limit: 268435456)
    ...
    OOM: Cannot reserve 8388608 bytes of direct buffer memory (allocated: 262144001, limit: 268435456)
    OOM: failed to allocate 8388608 byte(s) of direct memory (used: 262144000, max: 268435456)
    REPRODUCED: 32 thread(s) hit OOM

    Note: As I am not very deep on this, so this sample may not be correct for the root cause analysis.

  6. franz1981 commented on Jul 17, 2026

    @franz1981
    franz1981
    on Jul 17, 2026
    Contributor
    More actions

    In 4.2.16 I have added #16766 but the previous version was 4..2.14 instead.
    The reproducer is actually doing something similar to what your real app Is doing? Or is just throwing similarly OOM?

  7. topEngineerRay commented on Jul 17, 2026

    @topEngineerRay
    topEngineerRay
    on Jul 17, 2026
    Author
    More actions

    Its not doing the same for my application, just to throw the similar OOM.

    More infor can provide now:
    In the application we using spring webclient which in the end using netty AFAIK. There we have the following configuration:

    @configuration
    public class WebClientConfig {
    private static final String NETTY_HTTP_CLIENT_LOGGER_CATEGORY = "reactor.netty.http.client.HttpClient";

    @Value("${netty.http.client.wireLogger.enabled:false}")
    private boolean isHttpClientWireLoggerEnabled;
    
    @Bean
    public WebClient webClient(HttpClient httpClient, ExchangeStrategies exchangeStrategies) {
        return WebClient.builder()
                .clientConnector(new ReactorClientHttpConnector(httpClient))
                .exchangeStrategies(exchangeStrategies)
                .build();
    }
    
    @Bean
    public HttpClient nettyHttpClient(KeyManagerFactory keyManagerFactory) {
        ConnectionProvider provider =
                ConnectionProvider.builder("custom")
                        .maxConnections(100)
                        .lifo()
                        .maxIdleTime(Duration.ofSeconds(50)) // must be less than 60s
                        .evictInBackground(Duration.ofSeconds(120))
                        .build();
    
        ProtocolSslContextSpec protocolSslContextSpec = DefaultSslContextSpec.forClient()
                .configure(sslContextBuilder -> sslContextBuilder.sslProvider(SslProvider.JDK).keyManager(keyManagerFactory));
    
        HttpClient httpClient = HttpClient.create(provider)
                .secure(sslContextSpec -> sslContextSpec.sslContext(protocolSslContextSpec));
    
        if (isHttpClientWireLoggerEnabled) {
            httpClient = httpClient.wiretap(NETTY_HTTP_CLIENT_LOGGER_CATEGORY, DEBUG, TEXTUAL);
        }
    
        return httpClient;
    }
    

    }

    And use it as below in every places who needs to send a http request:

    @Value("${url}")
    private String serviceRpaUrl;
    
    @Autowired
    private WebClient webClient;
    
    public Mono<BusinessObject> getBusinessObject(String id) {
        return webClient
                .get()
                .uri(serviceRpaUrl + "/BusinessObject/{id}", id.toUpperCase())
                .accept(APPLICATION_JSON)
                .retrieve()
                .onStatus(httpStatusCode -> httpStatusCode == NOT_FOUND, clientResponse -> Mono.error(new BusinessObjectNotFoundException(id)))
                .bodyToMono(id.class);
    }
    
  8. franz1981 commented on Jul 17, 2026

    @franz1981
    franz1981
    on Jul 17, 2026
    Contributor
    More actions

    f44a88d doesn't fail on your reproducer, but 4.2.12 fail so I don't think is a valid reproducer, as you noted 🙏

  9. franz1981 commented on Jul 17, 2026

    @franz1981
    franz1981
    on Jul 17, 2026
    Contributor
    More actions

    @He-Pin
    if you can enable JFR allocation data on the failed instance will make it easier to understand the allocation pattern and what's off.
    If the reproducer is correct (which I haven't yet understood...), can you give me the specification of the machine where it is supposed to fail? Which exact version pass, which fail?

    Becauase the failing message was

    java.lang.OutOfMemoryError: Cannot reserve 139264 bytes of direct buffer memory (allocated: 268421167, limit: 268435456)
    

    which is a size class chunk allocation, but the test instead excercise the "buddy" allocation path (1 MB allocations!), which means a completely different use case.

    So please can you provide a better reproducer which hit the same problem? 🙏

    I need to understand which versions are affected because:

    • on 4.2.16 I have increased the size classes chunk capacity (min 129 slots) which can make such caches to be fatter and bloating memory
    • in 4.2.10 the 32K and 64K size classes were removed leading to more allocation on the shared buddy chunks, which is something observed to be bad in 4.2 per magazine cache #17047 I was investigating already

    @violetagg did you heard of similar failures on reactor after the upgrade to 4.2.16 with small core (and low memory- my guess) machines?

  10. topEngineerRay commented on Jul 17, 2026

    @topEngineerRay
    topEngineerRay
    on Jul 17, 2026
    Author
    More actions

    f44a88d doesn't fail on your reproducer, but 4.2.12 fail so I don't think is a valid reproducer, as you noted 🙏

    @franz1981 A further update: we notice that with 4.2.12.final we also got similar issue, direct memory continusly increase, we are currently trying to switch back to default netty version of spring boot which is 4.1.136.final.

    will share if we got further findings.
    Image

  11. franz1981 commented on Jul 17, 2026

    @franz1981
    franz1981
    on Jul 17, 2026
    Contributor
    More actions

    @topEngineerRay maybe you have some leak?
    Have you tried enabling leak detection? What happen if you set the pooled allocator as default?

  12. topEngineerRay commented on Jul 17, 2026

    @topEngineerRay
    topEngineerRay
    on Jul 17, 2026
    Author
    More actions
    Image

    The service has no related business logic change in past months. Only maven depdency update. And after we set the netty version to 4.2.16.final, the memory start to increase until that time its always stable. We do not have any directly JVM memory touch in the service, its fully manged by the dependency like netty.

    Btw, I found we also have this config in the WebClientConfig class:

    @bean
    public ExchangeStrategies exchangeStrategies(Jackson2ObjectMapperBuilder objectMapperBuilder) {
    ObjectMapper objectMapper = objectMapperBuilder.build();
    return ExchangeStrategies.builder().codecs(configurer -> {
    configurer.customCodecs().registerWithDefaultConfig(new Jackson2JsonEncoder(objectMapper));
    configurer.customCodecs().registerWithDefaultConfig(new Jackson2JsonDecoder(objectMapper));
    configurer.defaultCodecs().maxInMemorySize(-1);
    }).build();
    }

    maxInMemorySize(-1) means unbounded in-memory buffering of responses. Would this be related?

    • What happen if you set the pooled allocator as default?

    Does this mean change the httpclient config something like this?

    HttpClient httpClient = HttpClient.create(provider)
    .secure(sslContextSpec -> sslContextSpec.sslContext(protocolSslContextSpec))
    .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);

  13. franz1981 commented on Jul 17, 2026

    @franz1981
    franz1981
    on Jul 17, 2026
    Contributor
    More actions

    after we set the netty version to 4.2.16.final,

    But the previous version does have a similar problem just diluted over time, correct?
    (Unbounded increase in direct memory usage)

    Does this mean change the httpclient config something like this?

    Yes.

    In any case knowing the number of cores or memory settings would help.
    Most importantly a correct reproducer or is very hard to diagnose it, unless you collect way more telemetry (and heap dump? Or jfr from the allocator?)

    It could helps too if you can try custom branches I provide too.

  14. topEngineerRay commented on Jul 17, 2026

    @topEngineerRay
    topEngineerRay
    on Jul 17, 2026
    Author
    More actions

    But the previous version

    Just to make it clear: previous version is the default version of spring boot, which is 4.1.136.Final, we set it to 4.2.16.Final explicitly in that change.

    • number of cores getting via: Runtime.getRuntime().availableProcessors() is 1.

    • memory settings is: JAVA_OPTS: '-XX:MaxDirectMemorySize=256M'

    • jdk: 21

    • service instance memeoy : 2G

    • The rest config are default

    Will share later if could get a correct reproducer or a dump. unfortunately I could not make it for now.

    Reacted by Francesco Nigro
  15. franz1981 commented on Jul 17, 2026

    @franz1981
    franz1981
    on Jul 17, 2026
    Contributor
    More actions

    #17107 (comment)

    wow 1 core for a Java application is pretty...dangerous.

    In any case if you set -Xmx513m what happen?
    This should enable per event loop magazines, which could or not help -and enable shared buddy allocations instead of relying on one shot allocated off heap memory on the fly.

    Reacted by Stephane Landelle
    Reacted by Dmytro Dumanskiy
  16. 28 remaining items

  17. franz1981 commented on Aug 21, 2026

    @franz1981
    franz1981
    on Aug 21, 2026
    Contributor
    More actions

    And @topEngineerRay did you tried just

    -Dio.netty.tryReflectionSetAccessible=true
      --add-opens java.base/java.nio=ALL-UNNAMED
    

    ?

  18. topEngineerRay commented on Aug 21, 2026

    @topEngineerRay
    topEngineerRay
    on Aug 21, 2026
    Author
    More actions

    No, you mean without the -Dio.netty.allocator.lowMemory=false? like below?

    JAVA_OPTS: '-XX:MaxDirectMemorySize=256M -Dio.netty.tryReflectionSetAccessible=true --add-opens java.base/java.nio=ALL-UNNAMED'

    Is it worth trying this? what's your recomendation

  19. franz1981 commented on Aug 21, 2026

    @franz1981
    franz1981
    on Aug 21, 2026
    Contributor
    More actions

    you mean without the -Dio.netty.allocator.lowMemory=false

    Yes. Just using

    -Dio.netty.tryReflectionSetAccessible=true
      --add-opens java.base/java.nio=ALL-UNNAMED
    

    It is to narrow down what was your issue with :)

    Reacted by Ray, Ding
  20. topEngineerRay commented on Aug 21, 2026

    @topEngineerRay
    topEngineerRay
    on Aug 21, 2026
    Author
    More actions

    @franz1981 Okay, need to redeploy the application and trigger a test, please expect an update early next week.

  21. topEngineerRay commented on Aug 25, 2026

    @topEngineerRay
    topEngineerRay
    on Aug 25, 2026
    Author
    More actions

    @franz1981 Just using the java option below, we also got the same result, the direct pool usage is < 13MB

    -Dio.netty.tryReflectionSetAccessible=true
    --add-opens java.base/java.nio=ALL-UNNAMED

  22. franz1981 commented on Aug 25, 2026

    @franz1981
    franz1981
    on Aug 25, 2026
    Contributor
    More actions

    Great @topEngineerRay
    Last check would be: what if you downgrade to use 4.1.16 again but applying

    -Dio.netty.tryReflectionSetAccessible=true
    --add-opens java.base/java.nio=ALL-UNNAMED

    ?
    In this way we can prove if your problem was only the inability to rely on platform malloc/free alone.
    I would like to categorize properly this issue so this can help other users which hit this 🙏
    I can promise that's the very last test

  23. topEngineerRay commented on Aug 27, 2026

    @topEngineerRay
    topEngineerRay
    on Aug 27, 2026
    Author
    More actions

    @franz1981 I guess you should refer to 4.2.16 version, right?
    With 4.2.16 and the options below:

    -Dio.netty.tryReflectionSetAccessible=true
    --add-opens java.base/java.nio=ALL-UNNAMED
    

    We also got the same test result, direct pool usage is stable at 13MB, no increase during my test

    Reacted by Francesco Nigro
  24. franz1981 commented on Aug 27, 2026

    @franz1981
    franz1981
    on Aug 27, 2026
    Contributor
    More actions

    Yep, so I think you didn't had a problem with the allocator but with the way we interact with malloc/free

  25. topEngineerRay commented on Aug 27, 2026

    @topEngineerRay
    topEngineerRay
    on Aug 27, 2026
    Author
    More actions

    So basicaly we would still need these two java options when upgrade to latest netty version? Did I get it correct

  26. franz1981 commented on Aug 27, 2026

    @franz1981
    franz1981
    on Aug 27, 2026
    Contributor
    More actions

    we would still need these two java options when upgrade to latest netty version?

    AFAIK yes - @yawkat ? I think that's required no?

  27. topEngineerRay commented on Sep 7, 2026

    @topEngineerRay
    topEngineerRay
    on Sep 7, 2026
    Author
    More actions

    @franz1981 Once we got a clear guidance about the java options, I am fine to close this issue. Thanks a lot for your support!

    Reacted by Francesco Nigro
  28. franz1981 commented on Sep 7, 2026

    @franz1981
    franz1981
    on Sep 7, 2026
    Contributor
    More actions

    TLDR:

    1. the problem wasn't he pool changes
    2. you probably switched to a more modern OpenJDK version which requires, to access malloc/free the mentioned JVM args (see Direct pool OOM again with netty 4.2.16 #17107 (comment))
  29. franz1981 commented on Sep 22, 2026

    @franz1981
    franz1981
    on Sep 22, 2026
    Contributor
    More actions

    Can be closed @topEngineerRay ?

  30. franz1981 commented on Sep 28, 2026

    @franz1981
    franz1981
    on Sep 28, 2026
    Contributor
    More actions

    Closing it due to inactivity. Please reopen it if not right!

    Reacted by Ray, Ding
    Reacted by Ray, Ding
  31. franz1981
    closed this as completedon Sep 28, 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.