I'm getting a few ANRs reported by Android for *`W...
# squarelibraries
t
I'm getting a few ANRs reported by Android for
WaitForOtherNonDaemonThreadsToExit
in each case I have an OkHttp thread running. Any knowledge about such kind of issues ?
Anr:
Copy code
#00  pc 0x000000000004e8f0  /apex/com.android.runtime/lib64/bionic/libc.so (syscall+32)
  #01  pc 0x00000000003a9ae4  /apex/com.android.art/lib64/libart.so (art::ConditionVariable::WaitHoldingLocks(art::Thread*)+140)
  #02  pc 0x00000000007267c0  /apex/com.android.art/lib64/libart.so (art::ThreadList::WaitForOtherNonDaemonThreadsToExit(bool)+336)
  #03  pc 0x000000000034dc20  /apex/com.android.art/lib64/libart.so (art::JII::DestroyJavaVM(_JavaVM*)+32)
  #04  pc 0x00000000000ce520  /system/lib64/libandroid_runtime.so (android::AndroidRuntime::start(char const*, android::Vector<android::String8> const&, bool)+1032)
  #05  pc 0x0000000000002570  /system/bin/app_process64 (main+1304)
  #06  pc 0x000000000004a7d4  /apex/com.android.runtime/lib64/bionic/libc.so (__libc_init+100)
Thread code in thread.
Thread:
Copy code
"rm.b0 some.domain.name" tid=45 Native
  #00  pc 0x00000000000a6718  /apex/com.android.runtime/lib64/bionic/libc.so (recvfrom+8)
  #01  pc 0x00000000000298c8  /apex/com.android.art/lib64/libopenjdk.so (NET_Read+80)
  #02  pc 0x000000000002a440  /apex/com.android.art/lib64/libopenjdk.so (SocketInputStream_socketRead0+216)
  at java.net.SocketInputStream.socketRead0 (Native method)
  at java.net.SocketInputStream.socketRead (SocketInputStream.java:118)
  at java.net.SocketInputStream.read (SocketInputStream.java:173)
  at java.net.SocketInputStream.read (SocketInputStream.java:143)
  at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.readFromSocket (ConscryptEngineSocket.java:945)
  at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.processDataFromSocket (ConscryptEngineSocket.java:909)
  at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.readUntilDataAvailable (ConscryptEngineSocket.java:824)
  at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.read (ConscryptEngineSocket.java:797)
  at okio.InputStreamSource.read (JvmOkio.kt:94)
  at okio.AsyncTimeout$source$1.read (AsyncTimeout.kt:128)
  at okio.RealBufferedSource.request (RealBufferedSource.kt:206)
  at okio.RealBufferedSource.require (RealBufferedSource.kt:199)
  at okhttp3.internal.http2.Http2Reader.nextFrame (Http2Reader.kt:89)
  at okhttp3.internal.http2.Http2Connection$ReaderRunnable.invoke (Http2Connection.kt:618)
  at okhttp3.internal.http2.Http2Connection$ReaderRunnable.invoke (Http2Connection.kt:609)
  at okhttp3.internal.concurrent.TaskQueue$execute$1.runOnce (TaskQueue.kt:98)
  at okhttp3.internal.concurrent.TaskRunner.runTask (TaskRunner.kt:116)
  at okhttp3.internal.concurrent.TaskRunner.access$runTask (TaskRunner.kt:42)
  at okhttp3.internal.concurrent.TaskRunner$runnable$1.run (TaskRunner.kt:65)
  at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1137)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:637)
  at java.lang.Thread.run (Thread.java:1012)
It happens on Samsung/Xiaomi/Fairphone mostly Android 13 and a few Android 12. So I do not think this is an OEM issue 😞
y
OkHttp has a its own threads, related to the Dispatcher and active while there are connections, not just inflight calls.
You may want to explicitly shutdown OkHttp, to release these
As the link suggests, this shouldn't be necessary. But maybe something's been made stricter.
t
Hum but where would I do that on Android? I don't think there's a proper place to do that for each app stop.
y
I think it really depends why it's happening?
If you are just meant to avoid threads after your activities and services stop normally, maybe tied to lifecycle, even just evicting idle connections might be enough. If you really shutdown the client and then use it again you'll have a bad time. Hence the guidance, not to shutdown.
I'm sorry I don't have the answer, just giving some context for the threads running. It comes up a lot in OkHttp used in web servers or build systems.
t
This is an audio player so the user might restart the app with everything already down but the process. I have no idea why Android ANR on shutdown, but if it's the cause I have no proper place to call the okhttp shutdown :( Are those threads the connection pool one and just an evict would be enough?
y
You could try giving the dispatcher an executor service using Daemon threads. It may lead to corrupted caches etc.
Or in 5 alpha, you can turn on TaskRunner logging to see what's going on.
t
Unfortunately I can't repro. Just ANRs on Play Console. I'll just need to hope some users do contact me about it to try to debug then. Not yet migrated to 5. Thanks for the pointers. Is there big difference between http2 + SSL and http2 without ? Or http1.1? In terms of threads. Cause the ANR number are significant but I would expect them a lot worse if it was for all cases.
681 Views