OSDN Git Service

Zygote: Fix race condition on package preloads.
authorNarayan Kamath <narayan@google.com>
Mon, 3 Jul 2017 13:12:26 +0000 (14:12 +0100)
committerAndreas Gampe <agampe@google.com>
Thu, 14 Sep 2017 01:37:05 +0000 (18:37 -0700)
commita3d4230b92d69eb12c48f83689aeb27de992277d
tree435486c8e96e30d3b448f70469dd6d7804ddc98a
parentd763e341b5cbe7449e7acba7179715e817b48c03
Zygote: Fix race condition on package preloads.

Before this change, ZygoteProcess.preloadPackageForAbi returned
as soon as the command was written to the zygote socket and not
after the preload completed. This meant that there was a small
window of time before the server side of the socket polled its FDs
where a second command could be written to the zygote socket. This
would lead to only one of the commands being processed and the
other being dropped. The client side of that socket would then wait
forever for a response and bring down the system once the watchdog
timeout was hit.

Example failure case :
--------------
system_server:send command(preloadPackage)
system_server:send command(fork)
zygote:poll & process command(preloadPackage)  // the fork command is dropped.

Example of normal operation :
------------------
system_server:send command(preloadPackage)
zygote:poll & process command(preloadPackage)
system_server:send command(fork)
zygote:poll & process command(fork)

This change makes preloadPackageForAbi synchronous, which ensures
that each POLLIN event corresponds to precisely one command.

(cherry picked from commit 24a3306c32aa3860184025638f3abaab96cc9153)

Bug: 62886909
Bug: 13618569
Test: Manual
Contributed-By: yuqianyu@huawei.com
Merged-In: I83faf974c9a70a6ab18323f692c1981784e4c56a
Change-Id: I83faf974c9a70a6ab18323f692c1981784e4c56a
core/java/android/os/ZygoteProcess.java
core/java/com/android/internal/os/WebViewZygoteInit.java
core/java/com/android/internal/os/ZygoteConnection.java