Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential risk of easily overlooked resource leaks. #2229

Open
asuraiv opened this issue Nov 8, 2023 · 0 comments
Open

Potential risk of easily overlooked resource leaks. #2229

asuraiv opened this issue Nov 8, 2023 · 0 comments

Comments

@asuraiv
Copy link

asuraiv commented Nov 8, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant