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 #17107DescriptionWith 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) Activityfranz1981 commented on Jul 17, 2026 Without more details is not easy to help... He-Pin commented on Jul 17, 2026 Reacted by Francesco Nigro topEngineerRay commented on Jul 17, 2026 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.
Its a complex business application and can not share, I will see if I can reproduce with a sample service. topEngineerRay commented on Jul 17, 2026
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. topEngineerRay commented on Jul 17, 2026 @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. franz1981 commented on Jul 17, 2026 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? topEngineerRay commented on Jul 17, 2026 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);
}
franz1981 commented on Jul 17, 2026 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 commented on Jul 17, 2026 @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? topEngineerRay commented on Jul 17, 2026
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.
 franz1981 commented on Jul 17, 2026 @topEngineerRay maybe you have some leak?
Have you tried enabling leak detection? What happen if you set the pooled allocator as default? topEngineerRay commented on Jul 17, 2026
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);
franz1981 commented on Jul 17, 2026
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. topEngineerRay commented on Jul 17, 2026
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 franz1981 commented on Jul 17, 2026
#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 franz1981 commented on Aug 21, 2026 And @topEngineerRay did you tried just
-Dio.netty.tryReflectionSetAccessible=true
--add-opens java.base/java.nio=ALL-UNNAMED
? topEngineerRay commented on Aug 21, 2026 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 franz1981 commented on Aug 21, 2026
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 :) topEngineerRay commented on Aug 21, 2026 @franz1981 Okay, need to redeploy the application and trigger a test, please expect an update early next week. topEngineerRay commented on Aug 25, 2026 @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
franz1981 commented on Aug 25, 2026 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 topEngineerRay commented on Aug 27, 2026 @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 franz1981 commented on Aug 27, 2026 Yep, so I think you didn't had a problem with the allocator but with the way we interact with malloc/free topEngineerRay commented on Aug 27, 2026 So basicaly we would still need these two java options when upgrade to latest netty version? Did I get it correct franz1981 commented on Aug 27, 2026
we would still need these two java options when upgrade to latest netty version?
AFAIK yes - @yawkat ? I think that's required no? topEngineerRay commented on Sep 7, 2026 @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 franz1981 commented on Sep 7, 2026 franz1981 commented on Sep 22, 2026 franz1981 commented on Sep 28, 2026 Closing it due to inactivity. Please reopen it if not right! Reacted by Ray, Ding Reacted by Ray, Ding
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|