Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Abnormal CPU usage - Okio Watchdog

I am using OkHttp (first the original verison, then I upgraded to OkHttp3), some users of my App have been reporting significant battery life loss when the App isn't running.

I ran a profiler and this is the result:

profiler of App

As you can see, Okio Watchdog is running the whole time. At roughly the halfway point, my App is fully in the background. There are no HTTP tasks taking place at this point in time. I started profiling after the last HTTP task ended.

Is it normal that the Watchdog runs throughout like that? If so, am I right in assuming this thread is causing a lot of battery waste? If it isn't normal, could something like a leaked Context keep the Watchdog running?

The Watchdog code runs here, it seems like to runs without a termination condition:

private static final class Watchdog extends Thread {
    public Watchdog() {
        super("Okio Watchdog");
        setDaemon(true);
    }

    public void run() {
        while (true) {
            try {
                AsyncTimeout timedOut = awaitTimeout();

                // Didn't find a node to interrupt. Try again.
                if (timedOut == null) continue;

                // Close the timed out node.
                timedOut.timedOut();
            } catch (InterruptedException ignored) {
            }
        }
    }
}
like image 966
Knossos Avatar asked Apr 08 '26 10:04

Knossos


2 Answers

Looks like a severe & unexpected bug in Okio. I'll try to reproduce & fix. If you're able to produce this consistently, please comment on this bug!

https://github.com/square/okio/issues/185

like image 56
Jesse Wilson Avatar answered Apr 11 '26 00:04

Jesse Wilson


For me it was caused by proguard's optimization. After some investigation - see the okio issue linked above - a workaround (if not final fix?) is to disable optimization or add this to your proguard-rules.pro:

-optimizations !method/marking/static,!method/removal/parameter,!code/removal/advanced
like image 40
NeilS Avatar answered Apr 10 '26 23:04

NeilS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!