OutOfMemoryError (Direct Buffer Memory) in Spring Cloud Gateway on Java 21
search cancel

OutOfMemoryError (Direct Buffer Memory) in Spring Cloud Gateway on Java 21

book

Article ID: 435333

calendar_today

Updated On:

Products

VMware Tanzu Spring Essentials VMware Tanzu Platform Spring Essentials

Issue/Introduction

After upgrading a Spring Cloud Gateway application to Spring Cloud 2024.0.0, the application encounters a java.lang.OutOfMemoryError related to direct buffer memory allocation.

The application logs output the following error:

ERROR [<app-name>,,] [reactor-http-epoll-8] [629c9dd1] Error [reactor.netty.ReactorNetty$InternalNettyException: java.lang.OutOfMemoryError: Cannot reserve 65536 bytes of direct buffer memory (allocated: 10484501, limit: 10485760)] for HTTP POST "/xxxxxx/xxxxxx", but ServerHttpResponse already committed (200 OK)

Symptoms:

Large API requests complete successfully when the application first starts.

Over time, identical large requests begin to fail as the direct buffer memory limit is exhausted.

 

Note: This specific behavior and error trace was captured from an application running on TPCF (Tanzu Platform for Cloud Foundry).

Environment

Java: 21

Spring Cloud: 2024.0.0

Spring Boot: 3.4.x (Spring Framework 6.2)

Reactor Netty: 1.2.x

Library: spring-cloud-gateway

Platform: TPCF

Resolution

This error is caused by a known issue within the Spring Cloud 2024.0.0 release line. To resolve this and prevent direct memory exhaustion, upgrade your application's dependencies to the patched versions.

Action Required:

  • Update Spring Cloud to version 2024.0.2 (or higher).
  • Update Spring Boot to version 3.4.10 (or higher).