diff options
| author | Josh Gao <jmgao@google.com> | 2019-10-02 16:01:51 -0700 |
|---|---|---|
| committer | Josh Gao <jmgao@google.com> | 2019-10-03 17:18:04 +0000 |
| commit | 273613653fa9bdfd088cd11b19fcbb8ba1846f1e (patch) | |
| tree | 88b372fa447cdb95e7eee92e7e55f594b54b452f | |
| parent | b30f65713f70e0eb95062934826a763ed9b9fa39 (diff) | |
zygote: respond and wait for reply to --boot-completed.
The zygote handles requests by polling on its sockets, and then handling
one request for each active socket. However, it does so by reading from
a socket via a BufferedReader, which means that if multiple requests are
written into the socket before the zygote gets a chance to read them,
the zygote reads multiple requests into its BufferedReader, it handles
one request, and then never responds to the request that's buffered,
leaving its client stuck waiting for a response that will never happen.
For most requests, this can't happen, because the client will wait for a
response to be sent from the zygote before sending another request, but
this isn't true for --boot-completed until this patch.
Bug: http://b/141767463
Test: forrest runs of apct/text/text_native_test-cloud-tf
Change-Id: I8b7a80abfd9443d98f8cf5aedb7669b82c0cb84a
| -rw-r--r-- | core/java/android/os/ZygoteProcess.java | 1 | ||||
| -rw-r--r-- | core/java/com/android/internal/os/ZygoteConnection.java | 6 |
2 files changed, 7 insertions, 0 deletions
diff --git a/core/java/android/os/ZygoteProcess.java b/core/java/android/os/ZygoteProcess.java index e923336da454..3a55aff14659 100644 --- a/core/java/android/os/ZygoteProcess.java +++ b/core/java/android/os/ZygoteProcess.java @@ -760,6 +760,7 @@ public class ZygoteProcess { ZygoteState state = openZygoteSocketIfNeeded(abi); state.mZygoteOutputWriter.write("1\n--boot-completed\n"); state.mZygoteOutputWriter.flush(); + state.mZygoteInputStream.readInt(); } } catch (Exception ex) { throw new RuntimeException("Failed to inform zygote of boot_completed", ex); diff --git a/core/java/com/android/internal/os/ZygoteConnection.java b/core/java/com/android/internal/os/ZygoteConnection.java index c24ffb0c329b..b15e1efa46c8 100644 --- a/core/java/com/android/internal/os/ZygoteConnection.java +++ b/core/java/com/android/internal/os/ZygoteConnection.java @@ -305,6 +305,12 @@ class ZygoteConnection { } private void handleBootCompleted() { + try { + mSocketOutStream.writeInt(0); + } catch (IOException ioe) { + throw new IllegalStateException("Error writing to command socket", ioe); + } + VMRuntime.bootCompleted(); } |
