From def91c0abff84d6b51db507965cfb5f543538a80 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Tue, 31 Jul 2018 18:28:32 -0700 Subject: [PATCH] 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-), 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 ; adb connect ; adb shell true; done Change-Id: Ib55d304d7e07d6d744e8321d34671bb6d4b91afe --- adb/transport.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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 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); }