diff options
author | Josh Gao <jmgao@google.com> | 2016-12-12 18:15:33 -0800 |
---|---|---|
committer | Josh Gao <jmgao@google.com> | 2016-12-12 18:20:57 -0800 |
commit | f0f854bc76458b10b6b3ed88655fd87cd156dc70 (patch) | |
tree | f382e3ac76fa4a0391119d68fb0bb1a84fa5c0e4 /adb/client | |
parent | b0a15d83191c69f9a1279a09a40929b8b9fa6720 (diff) | |
download | system_core-f0f854bc76458b10b6b3ed88655fd87cd156dc70.tar.gz system_core-f0f854bc76458b10b6b3ed88655fd87cd156dc70.tar.bz2 system_core-f0f854bc76458b10b6b3ed88655fd87cd156dc70.zip |
adb: retry install_listener for a while.
install_listener can fail if we told a previous adb server to quit and
it hasn't finished doing so yet. Retry it for a few hundred
milliseconds to avoid this.
Bug: http://b/28618716
Test: nc -l 5037; adb server nodaemon
Change-Id: Ibbda8f2718b85a2b6a08985aa8d29aa2204a3ead
Diffstat (limited to 'adb/client')
-rw-r--r-- | adb/client/main.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/adb/client/main.cpp b/adb/client/main.cpp index 4ec0fc20d..d58351659 100644 --- a/adb/client/main.cpp +++ b/adb/client/main.cpp @@ -23,6 +23,8 @@ #include <stdlib.h> #include <unistd.h> +#include <thread> + #include <android-base/errors.h> #include <android-base/file.h> #include <android-base/logging.h> @@ -33,6 +35,7 @@ #include "adb_listeners.h" #include "adb_utils.h" #include "commandline.h" +#include "sysdeps/chrono.h" #include "transport.h" static std::string GetLogFilePath() { @@ -113,8 +116,18 @@ int adb_server_main(int is_daemon, const std::string& socket_spec, int ack_reply local_init(DEFAULT_ADB_LOCAL_TRANSPORT_PORT); std::string error; - if (install_listener(socket_spec, "*smartsocket*", nullptr, 0, nullptr, &error)) { - fatal("could not install *smartsocket* listener: %s", error.c_str()); + + auto start = std::chrono::steady_clock::now(); + + // If we told a previous adb server to quit because of version mismatch, we can get to this + // point before it's finished exiting. Retry for a while to give it some time. + while (install_listener(socket_spec, "*smartsocket*", nullptr, 0, nullptr, &error) != + INSTALL_STATUS_OK) { + if (std::chrono::steady_clock::now() - start > 0.5s) { + fatal("could not install *smartsocket* listener: %s", error.c_str()); + } + + std::this_thread::sleep_for(100ms); } if (is_daemon) { |