summaryrefslogtreecommitdiffstats
path: root/adb/fdevent.cpp
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2015-09-29 12:25:33 -0700
committerYabin Cui <yabinc@google.com>2015-09-30 15:03:26 -0700
commitaa77e22d7384a97757e2d2194f4e265f7ad3b71a (patch)
tree9fbcc3dbd66c1cdae1a50656b0e15e831eb6fc99 /adb/fdevent.cpp
parentd490db9824cdb4974da22ba80399f39a8b44ec08 (diff)
downloadsystem_core-aa77e22d7384a97757e2d2194f4e265f7ad3b71a.tar.gz
system_core-aa77e22d7384a97757e2d2194f4e265f7ad3b71a.tar.bz2
system_core-aa77e22d7384a97757e2d2194f4e265f7ad3b71a.zip
adb: detect sockets in CLOSE_WAIT state to prevent socket leak on linux.
It is possible that the adb server on host has many sockets in CLOSE_WAIT state. To prevent socket leak, always enable POLLRDHUP in fdevent.cpp to detect sockets in CLOSE_WAIT state. Update LocalSocketTest unit tests: Change half_close_with_packet to read_from_closing_socket, as reading from a SHUT_WR socket is not needed in adb. Change close_with_no_events_installed to close_socket_in_CLOSE_WAIT_state, as the latter is more close to the real situation in use. Bug: 23314034 Change-Id: Ice4f4036624e5584eab6ba5848e7f169c92f037f
Diffstat (limited to 'adb/fdevent.cpp')
-rw-r--r--adb/fdevent.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/adb/fdevent.cpp b/adb/fdevent.cpp
index 2de9386fd..2ffd908d4 100644
--- a/adb/fdevent.cpp
+++ b/adb/fdevent.cpp
@@ -58,6 +58,12 @@ struct PollNode {
PollNode(fdevent* fde) : fde(fde) {
memset(&pollfd, 0, sizeof(pollfd));
pollfd.fd = fde->fd;
+
+#if defined(__linux__)
+ // Always enable POLLRDHUP, so the host server can take action when some clients disconnect.
+ // Then we can avoid leaving many sockets in CLOSE_WAIT state. See http://b/23314034.
+ pollfd.events = POLLRDHUP;
+#endif
}
};
@@ -234,6 +240,11 @@ static void fdevent_process() {
// be detected at that point.
events |= FDE_READ | FDE_ERROR;
}
+#if defined(__linux__)
+ if (pollfd.revents & POLLRDHUP) {
+ events |= FDE_READ | FDE_ERROR;
+ }
+#endif
if (events != 0) {
auto it = g_poll_node_map.find(pollfd.fd);
CHECK(it != g_poll_node_map.end());