feign icon indicating copy to clipboard operation
feign copied to clipboard

Is the response.body().asInputStream loads whole file into memory?

Open huanyk opened this issue 1 year ago • 2 comments

I encountered an Out of Memory (OOM) error when using the response as a receiver while attempting to download a 6GB file. Upon investigation, I discovered that Feign doesn't seem to support downloading large files as inputstream.

final boolean shouldDisconnectResponseBody = response.body() != null
    && response.body().length() != null
    && response.body().length() <= MAX_RESPONSE_BUFFER_SIZE;
if (!shouldDisconnectResponseBody) {
  return response;
}

huanyk avatar Apr 22 '24 13:04 huanyk

Yes, that will happen with larger files when the return type of the proxied method is Response. This is so we can provide a complete object back to the caller. We do support large responses, by inspecting the Response Content-Length header. If it is larger than 8K, we do not load the data into memory.

If you are seeing the entire body being loaded into memory, check the Response headers to see what is being set and let us know.

kdavisk6 avatar Sep 11 '24 12:09 kdavisk6

Logger may read full response body into memory if your log level is HEADERS or FULL https://github.com/OpenFeign/feign/blob/a695cbaebb0fb71005020e3f037988bb3ac22f76/core/src/main/java/feign/Logger.java#L129

Nazukin-Dmitry avatar Sep 11 '24 13:09 Nazukin-Dmitry