facebook/fresco

HTTP error response when loading image results in leaked connection

Open

#1.983 aberto em 6 de dez. de 2017

Ver no GitHub
 (4 comments) (0 reactions) (0 assignees)Java (3.750 forks)batch import
buggood first issue

Métricas do repositório

Stars
 (17.072 stars)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

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

Guia do colaborador