Java heap space while wrapped response is read

Issue #408 new
Marc LEVISSE created an issue

While OpenApiValidationFilter wraps the response to be able to validate it, we sometimes face Java heap space error if response is a binary content response that is bigger than the available memory:

org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.OutOfMemoryError: Java heap space
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1082)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at com.atlassian.oai.validator.springmvc.OpenApiValidationFilter.doFilterInternal(OpenApiValidationFilter.java:61)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
    ...

Caused by: java.lang.OutOfMemoryError: Java heap space
    at org.springframework.util.FastByteArrayOutputStream.addBuffer(FastByteArrayOutputStream.java:304)
    at org.springframework.util.FastByteArrayOutputStream.write(FastByteArrayOutputStream.java:125)
    at org.springframework.web.util.ContentCachingResponseWrapper$ResponseServletOutputStream.write(ContentCachingResponseWrapper.java:242)
    ...

The issue is that we can not really customize the filtering to disable response wrapping when dealing with “binary” responses

The workaround we are setting up is to override the OpenApiValidationFilter with our own, that it customized to implement a way of skipping response validation on a list of exception (using url pattern)

Do you see a better way of dealing with those edge cases for the moment ?

Thx for your input

Comments (1)

  1. Sven Döring

    Are at least some responses validated? Or none of them?

    Do you have an example OpenAPI snippet having the response definition?

  2. Log in to comment