본문 바로가기
Issue

[Issue - Spring] DataBufferLimitException: Exceeded limit on max bytes to buffer : 262144 해결

by 잭피 2021. 12. 8.

Webclient를 쓰다가 아래와 같은 Exception이 발생

org.springframework.core.io.buffer.DataBufferLimitException: Exceeded limit on max bytes to buffer : 262144

몇몇 특정 검색어에서만 APM에서 발견되었다

원인은 in-memory buffer 256KB를 초과해서 익셉션이 발생한 것이다

 

Buffer Size

최근 스프링 부트버전에서 Webclient에 설정되는 default codec buffer size가 256KB로 변경되었다고 한다

Spring WebFlux 어플리케이션 메모리 문제를 피하기 위해 codec 처리를 위해 in-memory buffer 256KB가 default라고 한다 

(1KB → 1,024B), (256KB → 262,144B)

(한글의 경우: 최대 131,072자)

 

https://docs.spring.io/spring-framework/docs/current/reference/html/web-reactive.html#webflux

 

Web on Reactive Stack

The original web framework included in the Spring Framework, Spring Web MVC, was purpose-built for the Servlet API and Servlet containers. The reactive-stack web framework, Spring WebFlux, was added later in version 5.0. It is fully non-blocking, supports

docs.spring.io

해결

maxInMemorySize를 10MB로 바꿔주었다.

(참고 : -1로 줄 경우 unlimited 이다)

    @Primary
    @Bean
    WebClient.Builder webClient() {
        return WebClient.builder()
                .exchangeStrategies(ExchangeStrategies.builder()
                .codecs(configurer ->
                        configurer.defaultCodecs().maxInMemorySize(10 * 1024 * 1024 )).build());
    }

 

댓글