Skip to content

Always close an http response #101

@ben-manes

Description

@ben-manes

I am trying to track down a file descriptor leak, which so far empirically points to the getstream client as the only major infra change on those instances. I haven't identified directly, so am scanning over the code for possible causes.

One small nit is that this only closes the response if buildResponse does not fail. That can throw an IAE, among others. For peace of mind, it would be better to wrap all logic with a try-with-resources to ensure that the response is closed, rather than delay it and possibly leak, e.g. try (response) { ... }

public void onResponse(Call call, okhttp3.Response response) {
io.getstream.core.http.Response httpResponse = buildResponse(response);
try (InputStream ignored = httpResponse.getBody()) {
result.complete(httpResponse);
} catch (Exception e) {
result.completeExceptionally(e);
} finally {
response.body().close();
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions