From 78aae53eba419bd919c1db9002f1bceb434d2297 Mon Sep 17 00:00:00 2001 From: xi yu Date: Mon, 19 Dec 2022 08:27:33 +0000 Subject: [PATCH] [Bugfix] Add reading timeout when waiting for the reply of an application zygote. Some defective or bad application zygote processes may do much work or just sleep in their doPreload, which makes the ActivityManager:procStart thread of system_server blocked and the other applications can not start. Test: manual Change-Id: I5045718719a5f876e2a03b30f104096894c4c307 --- core/java/android/os/ZygoteProcess.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/java/android/os/ZygoteProcess.java b/core/java/android/os/ZygoteProcess.java index 3cb5c60259ebc..0b6a99b0ae98e 100644 --- a/core/java/android/os/ZygoteProcess.java +++ b/core/java/android/os/ZygoteProcess.java @@ -73,6 +73,8 @@ public class ZygoteProcess { private static final int ZYGOTE_CONNECT_TIMEOUT_MS = 20000; + private static final int APPLICATION_ZYGOTE_READ_TIMEOUT_MS = 5000; + /** * Use a relatively short delay, because for app zygote, this is in the critical path of * service launch. @@ -1109,6 +1111,9 @@ public class ZygoteProcess { state.mZygoteOutputWriter.flush(); + // The system_server should not be blocked by a defective or bad application zygote. + state.mZygoteSessionSocket.setSoTimeout(APPLICATION_ZYGOTE_READ_TIMEOUT_MS); + return (state.mZygoteInputStream.readInt() == 0); } }