facebook / facebook/fresco

HTTP error response when loading image results in leaked connection

Open
#1,983 4 comments 0 reactions 0 assignees View on GitHub
bug good first issue
Dominant language
Kotlin
Stars
17.2k
Forks
3.7k
PR merge metrics
No merged PRs in 30d

Description

### Description
I noticed a bunch of log lines like this throughout Logcat as I used my app:
`19098-19147/ W/OkHttpClient: A connection to was leaked. Did you forget to close a response body?`

I eventually narrowed it down to a single SimpleDraweeView that was causing it when I tried to set its image URI.

Using imagepipeline-okhttp3, I added an OkHTTP client and interceptor so I could inspect what was going on with the HTTP request/response. It turns out that the response was not 200, rather a 401 error. This prevented the image from loading as expected and also led to the above log lines.

I was able to fix this particular 401 error by using an interceptor to add the necessary authentication headers I was missing. However, I was wondering If there are different HTTP errors in the future, is there a general way to catch errors in such a way that it doesn't leak a connection?

### Reproduction
Set an image URI on a SimpleDraweeView that results in a 401 HTTP error code response.

### Additional Information
* Fresco version: 1.5.0
* imagepipeline-okhttp3 version: 1.5.0

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.