facebook/fresco

HTTP error response when loading image results in leaked connection

Open

#1 983 ouverte le 6 déc. 2017

Voir sur GitHub
 (4 commentaires) (0 réactions) (0 assignés)Java (3 750 forks)batch import
buggood first issue

Métriques du dépôt

Stars
 (17 072 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

Description

I noticed a bunch of log lines like this throughout Logcat as I used my app: 19098-19147/<package> W/OkHttpClient: A connection to <my server> 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

Guide contributeur