summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Gao <jmgao@google.com>2018-07-31 18:28:32 -0700
committerJosh Gao <jmgao@google.com>2018-07-31 18:28:32 -0700
commitdef91c0abff84d6b51db507965cfb5f543538a80 (patch)
tree42451d8d2fc4b4d4b8414e70baaf482ec508fa3c
parent258d4a91c962b182a6119a69b631269ee7ffba58 (diff)
adb: disable ReconnectHandler in adbd.
Previously, when a TCP connection was disconnected from adbd, we were registering it with ReconnectHandler, which led to the transport sticking around after the socket was closed. Due to the naming of TCP transports in adbd (host-<fd number>), this results in incoming connections being immediately closed if their file descriptor number ends up being the same as a TCP transport that had previously disconnected. Guard all of the reconnect logic with ADB_HOST, to fix this. Bug: http://b/112054041 Test: while true; do adb connect <device>; adb connect <device>; adb shell true; done Change-Id: Ib55d304d7e07d6d744e8321d34671bb6d4b91afe
-rw-r--r--adb/transport.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/adb/transport.cpp b/adb/transport.cpp
index b45c43f89..922200826 100644
--- a/adb/transport.cpp
+++ b/adb/transport.cpp
@@ -81,6 +81,7 @@ class SCOPED_CAPABILITY ScopedAssumeLocked {
~ScopedAssumeLocked() RELEASE() {}
};
+#if ADB_HOST
// Tracks and handles atransport*s that are attempting reconnection.
class ReconnectHandler {
public:
@@ -224,6 +225,8 @@ void ReconnectHandler::Run() {
static auto& reconnect_handler = *new ReconnectHandler();
+#endif
+
} // namespace
TransportId NextTransportId() {
@@ -697,9 +700,11 @@ static void transport_registration_func(int _fd, unsigned ev, void*) {
update_transports();
}
+#if ADB_HOST
void init_reconnect_handler(void) {
reconnect_handler.Start();
}
+#endif
void init_transport_registration(void) {
int s[2];
@@ -718,7 +723,9 @@ void init_transport_registration(void) {
}
void kick_all_transports() {
+#if ADB_HOST
reconnect_handler.Stop();
+#endif
// To avoid only writing part of a packet to a transport after exit, kick all transports.
std::lock_guard<std::recursive_mutex> lock(transport_lock);
for (auto t : transport_list) {
@@ -756,13 +763,19 @@ static void transport_unref(atransport* t) {
t->ref_count--;
if (t->ref_count == 0) {
t->connection()->Stop();
+#if ADB_HOST
if (t->IsTcpDevice() && !t->kicked()) {
- D("transport: %s unref (attempting reconnection) %d", t->serial.c_str(), t->kicked());
+ D("transport: %s unref (attempting reconnection)", t->serial.c_str());
reconnect_handler.TrackTransport(t);
} else {
D("transport: %s unref (kicking and closing)", t->serial.c_str());
remove_transport(t);
}
+#else
+ D("transport: %s unref (kicking and closing)", t->serial.c_str());
+ remove_transport(t);
+#endif
+
} else {
D("transport: %s unref (count=%zu)", t->serial.c_str(), t->ref_count);
}