okio icon indicating copy to clipboard operation
okio copied to clipboard

Exit Watchdog on InterruptedException

Open vsbogd opened this issue 6 years ago • 1 comments

I faced this issue writing code using web3j library which in turn uses okhttp and okio. After application finished few daemon threads keep running. One of them is "Okio Watchdog".

Maven exec plugin makes warning about that, waits for 15 seconds and kills threads:

WARNING] thread Thread[RxSchedulerPurge-1,5,org.web3j.test.Web3jTestApp] was interrupted but is still alive after waiting at least 15000msecs
[WARNING] thread Thread[RxSchedulerPurge-1,5,org.web3j.test.Web3jTestApp] will linger despite being asked to die via interruption
[WARNING] thread Thread[RxCachedWorkerPoolEvictor-1,5,org.web3j.test.Web3jTestApp] will linger despite being asked to die via interruption
[WARNING] thread Thread[OkHttp ConnectionPool,5,org.web3j.test.Web3jTestApp] will linger despite being asked to die via interruption
[WARNING] thread Thread[Okio Watchdog,5,org.web3j.test.Web3jTestApp] will linger despite being asked to die via interruption
[WARNING] NOTE: 4 thread(s) did not finish despite being asked to  via interruption. This is not a problem with exec:java, it is a problem with the running code. Although not serious, it should be remedied.
[WARNING] Couldn't destroy threadgroup org.codehaus.mojo.exec.ExecJavaMojo$IsolatedThreadGroup[name=org.web3j.test.Web3jTestApp,maxpri=10]
java.lang.IllegalThreadStateException

Stacktrace:

"Okio Watchdog" #17 daemon prio=5 os_prio=0 tid=0x00007fc97c478000 nid=0x27dcd1 in Object.wait() [0x00007fc9b6618000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x000000076ec7bb58> (a java.lang.Class for okio.AsyncTimeout)
        at okio.AsyncTimeout.awaitTimeout(AsyncTimeout.java:347)
        at okio.AsyncTimeout$Watchdog.run(AsyncTimeout.java:312)
        - locked <0x000000076ec7bb58> (a java.lang.Class for okio.AsyncTimeout)

Looking into okio code I see that okio.AsyncTimeout$Watchdog.run ignores InterruptedException. Is it made intentionally? What is the reason?

Okio version: 1.13.0 (but I see the latest one is affected as well) Original issue: https://github.com/web3j/web3j/issues/1085 Test app: https://github.com/web3j/web3j/issues/1085#issuecomment-549748777

vsbogd avatar Nov 16 '19 12:11 vsbogd

It’ll exit after 60 seconds of inactivity. Could probably trigger a sooner exit on interruption, though that needs implementation and tests.

We won’t exit the watchdog on interruption if any timeouts are pending.

swankjesse avatar Nov 18 '19 02:11 swankjesse