OpenFeign / OpenFeign/feign

Potential risk of easily overlooked resource leaks.

Open
#2,229 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Java
Stars
9.8k
Forks
1.9k
Avg merge
1d 2h
Merged PRs (30d)
41

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating disconnectResponseBodyIfNeeded and tracing feign.Response body ownership, especially when Content-Length is absent. Reproduce the Spring Framework MVC error-response case, then inspect existing response-handling tests and define the expected closure behavior before adding a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.