Application Fails to Start with "java.lang.OutOfMemoryError: Cannot reserve direct buffer memory" in Tanzu Application Service
search cancel

Application Fails to Start with "java.lang.OutOfMemoryError: Cannot reserve direct buffer memory" in Tanzu Application Service

book

Article ID: 427958

calendar_today

Updated On:

Products

VMware Tanzu Platform - Cloud Foundry VMware Tanzu Application Service VMware Tanzu Platform VMware Tanzu Platform Core VMware Tanzu Platform Spring VMware Tanzu Platform Spring Essentials

Issue/Introduction

Java applications running on Tanzu Application Service (TAS) may fail to start with an OutOfMemoryError related to direct buffer memory allocation. This issue commonly affects applications using Netty-based libraries such as Lettuce (Redis client), Spring WebFlux, or gRPC.

You might observe similar logs when you run cf logs on the app 

java.lang.OutOfMemoryError: Cannot reserve 8388608 bytes of direct buffer memory 
(allocated: 5625309, limit: 10485760)
    at java.base/java.nio.Bits.reserveMemory(Unknown Source)
    at java.base/java.nio.DirectByteBuffer.<init>(Unknown Source)
    at io.netty.buffer.UnpooledDirectByteBuf.allocateDirect(UnpooledDirectByteBuf.java:121)
    ...

 

Cause

The CF Java Buildpack Memory Calculator allocates a fixed default of 10MB for JVM direct memory (-XX:MaxDirectMemorySize=10M). This allocation is insufficient for applications that use Netty-based libraries, which rely heavily on direct memory buffers for I/O operations.

You would observer similar message from the staging logs 

2026-02-03T05:48:50.44-0500 [APP/PROC/WEB/0] OUT JVM Memory Configuration: -Xmx5481091K -Xss1M -XX:ReservedCodeCacheSize=240M -XX:MaxDirectMemorySize=10M -XX:MaxMetaspaceSize=298364K

Resolution

 

Solution 1: Set JAVA_OPTS Environment Variable (Quick Fix)

Increase the direct memory allocation by setting the JAVA_OPTS environment variable:

cf set-env <APP_NAME> JAVA_OPTS "-XX:MaxDirectMemorySize=256m"
cf restage <APP_NAME>

Note: This is ephemeral when you restage the app this will not be taken into effect.


Solution 2: Configure in manifest.yml (Persistent)

Add the configuration to your manifest.yml for consistent deployments:

applications:
  - name: my-application
    memory: 6G
    env:
      JAVA_OPTS: "-XX:MaxDirectMemorySize=256m"