-
Notifications
You must be signed in to change notification settings - Fork 753
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
StrictMode exception,http connection should be closed when no use . HurlStack.java #138
Comments
Looks like we never call HttpUrlConnection#disconnect. Seems like we should per the Javadoc. At a glance it seems like the easiest way would be to:
|
HttpUrlConnection#disconnect should also be called if |
If we are finished with the connection (on network error or empty response), close it before returning/throwing. If not (because the response body still needs to be read), wrap the returned InputStream in one which disconnects when the stream is closed. Fixes google#138
If we are finished with the connection (on network error or empty response), close it before returning/throwing. If not (because the response body still needs to be read), wrap the returned InputStream in one which disconnects when the stream is closed. Fixes google#138
For whatever reason I wasn't able to reproduce this strict mode violation, but I've prepared a fix that should be safe nonetheless in #176. Would appreciate if someone here could either validate the fix or provide more info on how to reproduce this (sample app and/or details of the platform that is being used). |
If we are finished with the connection (on network error or empty response), close it before returning/throwing. If not (because the response body still needs to be read), wrap the returned InputStream in one which disconnects when the stream is closed. Fixes #138
E/StrictMode: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'close' not called
at dalvik.system.CloseGuard.open(CloseGuard.java:180)
at java.net.AbstractPlainSocketImpl.create(AbstractPlainSocketImpl.java:103)
at java.net.Socket.createImpl(Socket.java:464)
at java.net.Socket.getImpl(Socket.java:530)
at java.net.Socket.setSoSndTimeout(Socket.java:1194)
at com.android.okhttp.Connection.setTimeouts(Connection.java:508)
at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:400)
at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:130)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:356)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:273)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:474)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:422)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:538)
at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)
at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java)
at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:110)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:97)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:114)
The text was updated successfully, but these errors were encountered: