CPU 使用异常 - Okio Watchdog

Abnormal CPU usage - Okio Watchdog

我正在使用 OkHttp(首先是原始版本,然后我升级到 OkHttp3),我的应用程序的一些用户报告说当应用程序不是 运行.

我 运行 一个分析器,这是结果:

如您所见,Okio Watchdog 一直处于 运行。大约在中途,我的应用程序完全处于后台。此时没有发生任何 HTTP 任务。我在最后一个 HTTP 任务结束后开始分析。

看门狗这样一直跑正常吗?如果是这样,我是否正确地假设此线程会导致大量电池浪费?如果不正常,是否可以像泄漏的 Context 这样的东西保留 Watchdog 运行?

Watchdog code运行到这里,好像没有终止条件运行:

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) {
            }
        }
    }
}

Okio 中似乎存在严重且意外的错误。我会尝试重现并修复。如果您能够始终如一地生成此错误,请对此错误发表评论!

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

对我来说,这是proguard 的优化造成的。经过一些调查 - 请参阅上面链接的 okio 问题 - 一种解决方法(如果不是最终修复?)是禁用优化或将其添加到您的混淆器中 -rules.pro:

-optimizations !method/marking/static,!method/removal/parameter,!code/removal/advanced

我在这个 manual

中找到了一个注释

Note: the configuration specifies that none of the methods of class '...' have any side effects

Your configuration contains an option -assumenosideeffects to indicate that the specified methods don't have any side effects. However, the configuration tries to match all methods, by using a wildcard like "*;". This includes methods from java.lang.Object, such as wait() and notify(). Removing invocations of those methods will most likely break your application. You should list the methods without side effects more conservatively. You can switch off these notes by specifying the -dontnote option.

您应该在 -assumenosideeffects 块中指定方法名称。

我在 https://github.com/square/okio/issues/185#issuecomment-220520926

添加此评论