Closed d4rken closed 7 years ago
I also seem to get it on BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(urlConnection.getOutputStream(), "UTF-8"));
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 com.android.org.conscrypt.Platform.closeGuardOpen(Platform.java:282)
at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:316)
at com.android.okhttp.Connection.connectTls(Connection.java:235)
at com.android.okhttp.Connection.connectSocket(Connection.java:199)
at com.android.okhttp.Connection.connect(Connection.java:172)
at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:367)
at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:130)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:329)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:246)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:457)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:126)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:257)
at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)
at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java)
at org.piwik.sdk.dispatcher.Dispatcher.dispatch(Dispatcher.java:210)
at org.piwik.sdk.dispatcher.Dispatcher$1.run(Dispatcher.java:159)
at java.lang.Thread.run(Thread.java:761)
@aegis123 always? or randomly? What Android version?
Im running 7.1.1 on a nexus 5x and it seems randomly.
the easiest fix seem to wrap it in a try catch and always close the BufferedWriter.
Seeing it too on 7.1.1, just on 7+.
I just noticed that we should close the stream in a finally
, depending on where an exception happens we might not close it. From my logs though, there was no exception before this strictmode warning, so I don't think this is the issue.
HttpURLConnection.getResponseCode()
opens another stream which we didn't close and if an exception happens, we didn't close the gzip stream either.
So this should now be fixed.
Originates from
int statusCode = urlConnection.getResponseCode();
.(line numbers from Dispatcher are not accurate in the stacktrace)
Only visible with:
First thought internal Android bug, but the same happens when using
okhttp:3.6.0
. Google fu shows lots of other reports, but no clear cut solution.Not really sure if this even is an issue, lets note this here for now.