Skip to content

Potential risk of easily overlooked resource leaks. #2229

Open
@asuraiv

Description

@asuraiv

Hello. I have a question about feign.Response. When I look at the following code, there is code that does not return a Response object under certain conditions.

private static Response disconnectResponseBodyIfNeeded(Response response) throws IOException {
  final boolean shouldDisconnectResponseBody = response.body() != null
      && response.body().length() != null
      && response.body().length() <= MAX_RESPONSE_BUFFER_SIZE;
  if (!shouldDisconnectResponseBody) {
    return response;
  }

  try {
    final byte[] bodyData = Util.toByteArray(response.body().asInputStream());
    return response.toBuilder().body(bodyData).build();
  } finally {
    ensureClosed(response.body());
  }
}

For example, in a Spring Framework-based MVC application, when there is an error response, the 'Content-Length' header is missing, and in such cases, the resource is not released. Is there a reason for the existence of this code, and could it be code that is not necessary?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionGeneral usage or 'how-to' questions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions