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

StrictMode exception,http connection should be closed when no use . HurlStack.java #138

Closed
businezcc opened this issue Jan 3, 2018 · 3 comments · Fixed by #176 or AndroidKotlinID/volley#23
Milestone

Comments

@businezcc
Copy link

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)

@jpd236
Copy link
Collaborator

jpd236 commented Jan 3, 2018

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:

  • Call disconnect directly in HurlStack#executeRequest if the response has no body
  • Wrap the InputStream returned by HurlStack#inputStreamFromConnection to call disconnect() from InputStream#close, so the connection is closed once the Network has consumed the stream contents. BasicNetwork#inputStreamToBytes does close the InputStream already AFAICT.

@jpd236 jpd236 added this to the 1.1.1 milestone Jan 3, 2018
@Yaun1234
Copy link

HttpUrlConnection#disconnect should also be called if connection.getResponseCode() throws an exception, e.g. a SocketTimeoutException.

jpd236 added a commit to jpd236/volley that referenced this issue May 3, 2018
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
jpd236 added a commit to jpd236/volley that referenced this issue May 3, 2018
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
@jpd236
Copy link
Collaborator

jpd236 commented May 3, 2018

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).

jpd236 added a commit that referenced this issue May 3, 2018
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants