Thursday, June 19, 2014

Bug - WatchDog timout


  • RootCause
    • watchdog will schedule a check to acquire the lock, if can't get the lock then report timeout.
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), Blocked in handler on WindowManager thread (WindowManager)
 W Watchdog: foreground thread stack trace:
 W Watchdog:     at com.android.server.am.ActivityManagerService.monitor(ActivityManagerService.java:16009)
.........
 W Watchdog: ActivityManager stack trace:
 W Watchdog:     at com.android.server.am.ActivityStack$ActivityStackHandler.handleMessage(ActivityStack.java:292)

    •    Usually we can see it if deadlock, trace the traces.txt,  there is a deadlock b/w threads.

"Binder_C" prio=5 tid=58 MONITOR
  | group="main" sCount=1 dsCount=0 obj=0x425af1d0 self=0x732d34b0
  | sysTid=1171 nice=-8 sched=0/0 cgrp=apps handle=1932210896
  | state=S schedstat=( 3712885896 3165563645 19485 ) utm=285 stm=85 core=0
  at com.android.server.wm.WindowManagerService.moveTaskToTop(WindowManagerService.java:~4792)
  - waiting to lock <0x424aea70> (a java.util.HashMap) held by tid=57 (Binder_B)
......
"Binder_B" prio=5 tid=57 MONITOR
  | group="main" sCount=1 dsCount=0 obj=0x4279b7c8 self=0x6c452620
  | sysTid=1134 nice=0 sched=0/0 cgrp=apps handle=1816469512
  | state=S schedstat=( 5136093661 3481006328 21082 ) utm=419 stm=94 core=0
  at com.android.server.am.ActivityManagerService.broadcastIntent(ActivityManagerService.java:~13693)
  - waiting to lock <0x42033500> (a com.android.server.am.ActivityManagerService) held by tid=58 (Binder_C)

    •     Check the source code, you can find below.

     * NOTE: Never call into methods that lock ActivityManagerService while holding this object.
*/
final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
  • Solution.
    • Process/Thread who cause the resource lock should rewrite the code to prevent the case like this.
  • Note about WatchDog
    • Service have to add itself to the monitor by Watchdog.getInstance().addMonitor(this) or addThread. Service also need to implement the monitor function to simply lock the service object itself.
    • If addMonitor, it will be added into the default foreground thread main checker. For others will create a new checker like UiThread, IoThread, Main looper.
    • WatchDog will query the lock and stop if timeout.

No comments:

Post a Comment