summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhangjianqiu <zhangjianqiu@oppo.com>2021-11-16 16:46:13 +0800
committeralk3pInjection <webmaster@raspii.tech>2022-01-27 18:50:18 +0800
commitf3b3ace29be7d7708f7578ee4f804381391bcf10 (patch)
treeba5c2a966ed316e2daa6c4d547afa78e33484ec4
parent0c8573cb3fbd35104e0274430349d414a35f0b5a (diff)
Zygote: Fix an issue when empty the usap pool
When empty the usap pool, the usap processes may be blocked by usapPoolSocket.accept(), which cause the usap process fail to kill immediately. So we can move the position of blockSigTerm after usapPoolsSocket.accept() and delele the old blockSigTerm in the while loop. Test: manual test. 1.setprop persist.device_config.runtime_native.usap_pool_enabled true. After 1 min, trigger fill usap pools. 2.setprop persist.device_config.runtime_native.usap_pool_enabled false. After 1 min, trigger empty usap pools. 3.repeat step 1. Signed-off-by: zhangjianqiu <zhangjianqiu@oppo.com> Change-Id: I657940b30f71cdc717c673be6d70738e61e2bb68
-rw-r--r--core/java/com/android/internal/os/Zygote.java10
1 files changed, 6 insertions, 4 deletions
diff --git a/core/java/com/android/internal/os/Zygote.java b/core/java/com/android/internal/os/Zygote.java
index 92d5a47a2ed0..6d4b8c5ea1ad 100644
--- a/core/java/com/android/internal/os/Zygote.java
+++ b/core/java/com/android/internal/os/Zygote.java
@@ -724,9 +724,6 @@ public final class Zygote {
DataOutputStream usapOutputStream = null;
ZygoteArguments args = null;
- // Block SIGTERM so we won't be killed if the Zygote flushes the USAP pool.
- blockSigTerm();
-
LocalSocket sessionSocket = null;
if (argBuffer == null) {
// Read arguments from usapPoolSocket instead.
@@ -742,6 +739,10 @@ public final class Zygote {
ZygoteCommandBuffer tmpArgBuffer = null;
try {
sessionSocket = usapPoolSocket.accept();
+ // Block SIGTERM so we won't be killed if the Zygote flushes the USAP pool.
+ // This is safe from a race condition because the pool is only flushed after
+ // the SystemServer changes its internal state to stop using the USAP pool.
+ blockSigTerm();
usapOutputStream =
new DataOutputStream(sessionSocket.getOutputStream());
@@ -759,9 +760,10 @@ public final class Zygote {
unblockSigTerm();
IoUtils.closeQuietly(sessionSocket);
IoUtils.closeQuietly(tmpArgBuffer);
- blockSigTerm();
}
} else {
+ // Block SIGTERM so we won't be killed if the Zygote flushes the USAP pool.
+ blockSigTerm();
try {
args = ZygoteArguments.getInstance(argBuffer);
} catch (Exception ex) {