看门狗超时杀死ActivityManager

时间:2016-09-13 05:00:16

标签: android

我们在捕获bug报告时看到随机重启。 从跟踪中,Binder持有一个锁并执行一些文件操作,而活动管理器等待在释放时获得相同的锁。 但由于某种原因,Binder未能在规定的60秒(看门狗超时时间)内完成操作,之后看门狗会启动并杀死活动管理器导致重启。 不确定文件操作失败的原因。 任何的想法??

****Logcat****
28429 28736 W Watchdog: *** WATCHDOG KILLING SYSTEM PROCESS: Blocked in monitor com.android.server.am.ActivityManagerService on foreground thread (android.fg), Blocked in handler on ActivityManager (ActivityManager)
28429 28736 W Watchdog: foreground thread stack trace:
28429 28736 W Watchdog: at com.android.server.am.ActivityManagerService.monitor(ActivityManagerService.java :18792)
28429 28736 W Watchdog:     at com.android.server.Watchdog$HandlerChecker.run(Watchdog.java:173)
28429 28736 W Watchdog:     at android.os.Handler.handleCallback(Handler.java:739)
28429 28736 W Watchdog:     at android.os.Handler.dispatchMessage(Handler.java:95)
28429 28736 W Watchdog:     at android.os.Looper.loop(Looper.java:135)
28429 28736 W Watchdog:     at android.os.HandlerThread.run(HandlerThread.java:61)
28429 28736 W Watchdog:     at com.android.server.ServiceThread.run(ServiceThread.java:46)
28429 28736 W Watchdog: ActivityManager stack trace:
28429 28736 W Watchdog:     at com.android.server.am.BatteryStatsService.noteProcessState(BatteryStatsService.java:159)
28429 28736 W Watchdog:     at com.android.server.am.ActivityManagerService.setProcessTrackerStateLocked(ActivityManagerService.java:18077)
28429 28736 W Watchdog:     at com.android.server.am.ActivityManagerService.updateOomAdjLocked(ActivityManagerService.java:18503)
28429 28736 W Watchdog:     at com.android.server.am.BroadcastQueue.processCurBroadcastLocked(BroadcastQueue.java:234)
28429 28736 W Watchdog:     at com.android.server.am.BroadcastQueue.processNextBroadcast(BroadcastQueue.java:893)
28429 28736 W Watchdog:     at com.android.server.am.BroadcastQueue$BroadcastHandler.handleMessage(BroadcastQueue.java:149)
28429 28736 W Watchdog:     at android.os.Handler.dispatchMessage(Handler.java:102)
28429 28736 W Watchdog:     at android.os.Looper.loop(Looper.java:135)
28429 28736 W Watchdog:     at android.os.HandlerThread.run(HandlerThread.java:61)
28429 28736 W Watchdog:     at com.android.server.ServiceThread.run(ServiceThread.java:46)
28429 28736 W Watchdog: *** GOODBYE!

****Traces****
"ActivityManager" prio=5 tid=14 Blocked
 | group="main" sCount=1 dsCount=0 obj=0x12d49d60 self=0xb4835000
 | sysTid=28447 nice=-2 cgrp=default sched=0/0 handle=0xb48ab400
 | state=S schedstat=( 122941894282 79694427844 199108 ) utm=7937 stm=4357 core=0 HZ=100
 | stack=0xa4dd4000-0xa4dd6000 stackSize=1036KB
 | held mutexes=
 at com.android.server.am.BatteryStatsService.noteProcessState(BatteryStatsService.java:159)
 - waiting to lock <0x1630e0b8> (a com.android.internal.os.BatteryStatsImpl) held by thread 63
 at com.android.server.am.ActivityManagerService.setProcessTrackerStateLocked(ActivityManagerService.java:18077)
 at com.android.server.am.ActivityManagerService.updateOomAdjLocked(ActivityManagerService.java:18503)
 at com.android.server.am.BroadcastQueue.processCurBroadcastLocked(BroadcastQueue.java:234)
 at com.android.server.am.BroadcastQueue.processNextBroadcast(BroadcastQueue.java:893)
 - locked <0x1d97ee91> (a com.android.server.am.ActivityManagerService)
 at com.android.server.am.BroadcastQueue$BroadcastHandler.handleMessage(BroadcastQueue.java:149)
 at android.os.Handler.dispatchMessage(Handler.java:102)
 at android.os.Looper.loop(Looper.java:135)
 at android.os.HandlerThread.run(HandlerThread.java:61)
 at com.android.server.ServiceThread.run(ServiceThread.java:46)

"Binder_7" prio=5 tid=63 Native`enter code here`
 | group="main" sCount=1 dsCount=0 obj=0x13057400 self=0xa3867000
 | sysTid=28848 nice=-20 cgrp=default sched=0/0 handle=0xb0052280
 | state=S schedstat=( 99308593770 7649047774 35537 ) utm=9244 stm=686 core=1 HZ=100
 | stack=0xa06db000-0xa06dd000 stackSize=1012KB
 | held mutexes=
 kernel: (couldn't read /proc/self/task/28848/stack)
 native: #00 pc 000133c4  /system/lib/libc.so (syscall+28)
 native: #01 pc 000a983f  /system/lib/libart.so (_ZN3art17ConditionVariable4WaitEPNS_6ThreadE+82)
 native: #02 pc 001b187f  /system/lib/libart.so (_ZN3art3JNI12NewStringUTFEP7_JNIEnvPKc+738)
 native: #03 pc 00018849  /system/lib/libjavacore.so (???)
 native: #04 pc 0001e66d  /system/lib/libjavacore.so (???)
 native: #05 pc 0001e743  /system/lib/libjavacore.so (???)
 native: #06 pc 00020b4f  /system/lib/libjavacore.so (???)
 native: #07 pc 0027a9a3  /data/dalvik-cache/arm/system@framework@boot.oat (Java_libcore_io_Posix_writeBytes__Ljava_io_FileDescriptor_2Ljava_lang_Object_2II+142)
 at libcore.io.Posix.writeBytes(Native method)
 at libcore.io.Posix.write(Posix.java:258)
 at libcore.io.BlockGuardOs.write(BlockGuardOs.java:313)
 at libcore.io.IoBridge.write(IoBridge.java:497)
 at java.io.FileOutputStream.write(FileOutputStream.java:186)
 at com.android.internal.util.FastPrintWriter.flushBytesLocked(FastPrintWriter.java:334)
 at com.android.internal.util.FastPrintWriter.flushLocked(FastPrintWriter.java:355)
 at com.android.internal.util.FastPrintWriter.appendLocked(FastPrintWriter.java:303)
 at com.android.internal.util.FastPrintWriter.print(FastPrintWriter.java:466)
 - locked <@addr=0x130f2630> (a com.android.internal.util.FastPrintWriter$DummyWriter)
 at android.os.BatteryStats.printBitDescriptions(BatteryStats.java:3427)
 at android.os.BatteryStats$HistoryPrinter.printNextItem(BatteryStats.java:3653)
 at android.os.BatteryStats.dumpHistoryLocked(BatteryStats.java:3907)
 at android.os.BatteryStats.dumpCheckinLocked(BatteryStats.java:4110)
 at com.android.server.am.BatteryStatsService.dump(BatteryStatsService.java:933)
 - locked <0x1630e0b8> (a com.android.internal.os.BatteryStatsImpl)
 at android.os.Binder.dump(Binder.java:319)
 at android.os.Binder.onTransact(Binder.java:285)
 at com.android.internal.app.IBatteryStats$Stub.onTransact(IBatteryStats.java:832)
 at android.os.Binder.execTransact(Binder.java:446)

1 个答案:

答案 0 :(得分:0)

虽然这是一篇非常古老的帖子,但偶然发现了类似的问题,其中活动管理器被Watchdog杀死了。然而,在我的情况下,问题结果是低系统内存,其中低记忆杀手被调用。由于没有完整的转储状态,我可以提供以下建议:

如果您能够解决问题,请发布您的观点。

如果预计bug报告很大或涉及一些网络操作,我们可以尝试增加看门狗提供给阻塞线程完成的“额外时间”。

https://android.googlesource.com/platform/frameworks/base/+/7e361d2/services/java/com/android/server/Watchdog.java

@Override
public void run() {

...

// Give some extra time to make sure the stack traces get written.
        // The system's been hanging for a minute, another second or two won't hurt much.
        SystemClock.sleep(2000);

最后,为了调试根本原因,如果我们附加调试器,看门狗将不会终止ActivityManager。

// Only kill the process if the debugger is not attached.
        if (Debug.isDebuggerConnected()) {
            Slog.w(TAG, "Debugger connected: Watchdog is *not* killing the system process");
        }