Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP error response when loading image results in leaked connection #1983

Open
stephen-workpop opened this issue Dec 6, 2017 · 4 comments
Open

Comments

@stephen-workpop
Copy link

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
@foghina foghina added the bug label Dec 7, 2017
@foghina
Copy link
Contributor

foghina commented Dec 7, 2017

Thank you for the report! We don't use OkHttp internally so this is fairly low priority for us. Feel free to send a pull request though!

@stephen-workpop
Copy link
Author

stephen-workpop commented Dec 7, 2017

@foghina Can you explain to me how Fresco was using OkHttp even before I included the imagepipeline-okhttp3 dependency? I was receiving the log line above when using the default settings for Fresco (not using the OkHttp image pipeline config). I even went through my build.gradle file and made sure to explicitly exclude OkHttp as a transitive dependency on all other dependencies. I then ran gradle app:dependencies and inspected the dependency tree to make sure that OkHttp was not part of it. I still somehow got the log line complaining about a leak OkHttp connection when Fresco loaded the problem image. Is OkHttp used internally by the Android system? I don't see how else it could have been in the logs if I wasn't including it as a dependency and neither was Fresco. I would assume that if OkHttp was not included as a dependency or explicitly set in the Fresco config, internally, Fresco would just use the Apache HTTP client or HttpURLConnection, which is built into Android itself, instead.

@stephen-workpop
Copy link
Author

Oh, here is a tweet from Jake Wharton himself saying that OkHttp is in fact part of the system as of Android v4.4: https://twitter.com/JakeWharton/status/482563299511250944

I guess that is how HttpUrlConnection is implemented.

@foghina
Copy link
Contributor

foghina commented Dec 8, 2017

Oh, sweet. I had no idea 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants