Open RyanRamchandar opened 6 years ago
These warnings seemed to have resurfaced after: #14
Hi, can you share how do you set the StrictMode, I tried with
StrictMode.enableDefaults();
And
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().build());
Could not manage to see any StrictMode complains.
Also seems that should be safe to do call.cancel() from Main thread, it used to be an issue but now is fixed https://github.com/square/okhttp/issues/1592
From OkHttp docs
Calls can be canceled from any thread. This will fail the call if it hasn’t yet completed! Code that is writing the request body or reading the response body will suffer an IOException when its call is canceled.
@skimarxall we setup Strict mode like so:
StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyLog()
.build())
StrictMode.setVmPolicy(StrictMode.VmPolicy.Builder()
.detectAll()
.penaltyLog()
.build())
I did not try the VM policy either with the penalty log, I will, but as mentioned in the other comment is it safe to call cancel from any thread
I think my PR is resolving this. https://github.com/heremaps/oksse/pull/24
I just merged the fix, please try the new version and let me know if the warning is solved
Seems like problem still exists.
@kashesoft could you make sure you are using the last version and if so, copy the logcat and the strict policy configuration you are using?
Yes, we are using
StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyLog()
.build())
StrictMode.setVmPolicy(StrictMode.VmPolicy.Builder()
.detectAll()
.penaltyLog()
.build())
Logcat:
10-09 09:35:52.799 20249-20969/co.umbrela.launcher.debug 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 'response.body().close()' not called
at dalvik.system.CloseGuard.open(CloseGuard.java:184)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at okhttp3.internal.platform.AndroidPlatform$CloseGuard.createAndOpen(AndroidPlatform.java:340)
at okhttp3.internal.platform.AndroidPlatform.getStackTraceForCloseable(AndroidPlatform.java:155)
at okhttp3.RealCall.captureCallStackTrace(RealCall.java:89)
at okhttp3.RealCall.enqueue(RealCall.java:98)
at com.here.oksse.RealServerSentEvent.enqueue(RealServerSentEvent.java:70)
at com.here.oksse.RealServerSentEvent.connect(RealServerSentEvent.java:50)
at com.here.oksse.OkSse.newServerSentEvent(OkSse.java:90)
...
The following code throws a StrictMode error:
Version: