summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Gao2018-07-31 20:28:32 -0500
committerJosh Gao2018-07-31 20:28:32 -0500
commitdef91c0abff84d6b51db507965cfb5f543538a80 (patch)
tree42451d8d2fc4b4d4b8414e70baaf482ec508fa3c
parent258d4a91c962b182a6119a69b631269ee7ffba58 (diff)
downloadplatform-system-core-def91c0abff84d6b51db507965cfb5f543538a80.tar.gz
platform-system-core-def91c0abff84d6b51db507965cfb5f543538a80.tar.xz
platform-system-core-def91c0abff84d6b51db507965cfb5f543538a80.zip
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 {
81 ~ScopedAssumeLocked() RELEASE() {} 81 ~ScopedAssumeLocked() RELEASE() {}
82}; 82};
83 83
84#if ADB_HOST
84// Tracks and handles atransport*s that are attempting reconnection. 85// Tracks and handles atransport*s that are attempting reconnection.
85class ReconnectHandler { 86class ReconnectHandler {
86 public: 87 public:
@@ -224,6 +225,8 @@ void ReconnectHandler::Run() {
224 225
225static auto& reconnect_handler = *new ReconnectHandler(); 226static auto& reconnect_handler = *new ReconnectHandler();
226 227
228#endif
229
227} // namespace 230} // namespace
228 231
229TransportId NextTransportId() { 232TransportId NextTransportId() {
@@ -697,9 +700,11 @@ static void transport_registration_func(int _fd, unsigned ev, void*) {
697 update_transports(); 700 update_transports();
698} 701}
699 702
703#if ADB_HOST
700void init_reconnect_handler(void) { 704void init_reconnect_handler(void) {
701 reconnect_handler.Start(); 705 reconnect_handler.Start();
702} 706}
707#endif
703 708
704void init_transport_registration(void) { 709void init_transport_registration(void) {
705 int s[2]; 710 int s[2];
@@ -718,7 +723,9 @@ void init_transport_registration(void) {
718} 723}
719 724
720void kick_all_transports() { 725void kick_all_transports() {
726#if ADB_HOST
721 reconnect_handler.Stop(); 727 reconnect_handler.Stop();
728#endif
722 // To avoid only writing part of a packet to a transport after exit, kick all transports. 729 // To avoid only writing part of a packet to a transport after exit, kick all transports.
723 std::lock_guard<std::recursive_mutex> lock(transport_lock); 730 std::lock_guard<std::recursive_mutex> lock(transport_lock);
724 for (auto t : transport_list) { 731 for (auto t : transport_list) {
@@ -756,13 +763,19 @@ static void transport_unref(atransport* t) {
756 t->ref_count--; 763 t->ref_count--;
757 if (t->ref_count == 0) { 764 if (t->ref_count == 0) {
758 t->connection()->Stop(); 765 t->connection()->Stop();
766#if ADB_HOST
759 if (t->IsTcpDevice() && !t->kicked()) { 767 if (t->IsTcpDevice() && !t->kicked()) {
760 D("transport: %s unref (attempting reconnection) %d", t->serial.c_str(), t->kicked()); 768 D("transport: %s unref (attempting reconnection)", t->serial.c_str());
761 reconnect_handler.TrackTransport(t); 769 reconnect_handler.TrackTransport(t);
762 } else { 770 } else {
763 D("transport: %s unref (kicking and closing)", t->serial.c_str()); 771 D("transport: %s unref (kicking and closing)", t->serial.c_str());
764 remove_transport(t); 772 remove_transport(t);
765 } 773 }
774#else
775 D("transport: %s unref (kicking and closing)", t->serial.c_str());
776 remove_transport(t);
777#endif
778
766 } else { 779 } else {
767 D("transport: %s unref (count=%zu)", t->serial.c_str(), t->ref_count); 780 D("transport: %s unref (count=%zu)", t->serial.c_str(), t->ref_count);
768 } 781 }