From c8ad0ca69d52cd53e30d1fb7dcbf93dd614db8ee Mon Sep 17 00:00:00 2001 From: Spencer Low <CompareAndSwap@gmail.com> Date: Wed, 29 Aug 2018 15:46:47 -0700 Subject: [PATCH] adb: really make kill-server wait for server death It doesn't seem like b3c14ec693d4c061fc9ec7fdaa7897169d179479 was really waiting for adb server death because the server would write OKAY to the socket, causing the client to return from ReadOrderlyShutdown() before the socket was actually closed. The fix is to read the OKAY and then call ReadOrderlyShutdown() which will then wait for the socket to be closed. Test: Made the server hang in adb_server_cleanup() during kill-server and kill-server would hang (as desired). Test: To test resilience, tried preventing the server from sending OKAY and adb kill-server still worked properly. Change-Id: I4f0f11b86bbdc983670273ef5d3bb1dff7ab3697 Signed-off-by: Spencer Low <CompareAndSwap@gmail.com> --- adb/client/adb_client.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/adb/client/adb_client.cpp b/adb/client/adb_client.cpp index 1959258b98..eda4b778a2 100644 --- a/adb/client/adb_client.cpp +++ b/adb/client/adb_client.cpp @@ -185,6 +185,11 @@ bool adb_kill_server() { return false; } + // The server might send OKAY, so consume that. + char buf[4]; + ReadFdExactly(fd, buf, 4); + // Now that no more data is expected, wait for socket orderly shutdown or error, indicating + // server death. ReadOrderlyShutdown(fd); return true; } -- GitLab