summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Tao Wu <lepton@google.com> 2017-01-08 01:20:21 -0800
committer Tao Wu <lepton@google.com> 2017-01-09 13:56:49 -0800
commit48fe7948f235efc52a219a2724d9902b54d80dfa (patch)
treef1e17c9744d464e6a09499a4e12572a3ea30c6c2
parent91db41f315f6c2366b7098c531224bee01170364 (diff)
Set timeout before connect to adb in jdwp.
Sometimes adb is in buggy status and just doesn't accept our connection. Add a timeout in art side to make sure we aren't stuck there. Bug: 34140694 Test: mma -j40 test-art-host Test: ./art/tools/run-jdwp-tests.sh --mode=host --variant=X64 Change-Id: Ia7756d5c03b57e87fe9642b0d32728aa6cead65c Signed-off-by: Tao Wu <lepton@google.com>
-rw-r--r--runtime/jdwp/jdwp_adb.cc16
1 files changed, 14 insertions, 2 deletions
diff --git a/runtime/jdwp/jdwp_adb.cc b/runtime/jdwp/jdwp_adb.cc
index d8869ad677..b13d565ec2 100644
--- a/runtime/jdwp/jdwp_adb.cc
+++ b/runtime/jdwp/jdwp_adb.cc
@@ -47,8 +47,16 @@
* JDWP-handshake, etc...
*/
-#define kJdwpControlName "\0jdwp-control"
-#define kJdwpControlNameLen (sizeof(kJdwpControlName)-1)
+static constexpr char kJdwpControlName[] = "\0jdwp-control";
+static constexpr size_t kJdwpControlNameLen = sizeof(kJdwpControlName) - 1;
+/* This timeout is for connect/send with control socket. In practice, the
+ * connect should never timeout since it's just connect to a local unix domain
+ * socket. But in case adb is buggy and doesn't respond to any connection, the
+ * connect will block. For send, actually it would never block since we only send
+ * several bytes and the kernel buffer is big enough to accept it. 10 seconds
+ * should be far enough.
+ */
+static constexpr int kControlSockSendTimeout = 10;
namespace art {
@@ -224,6 +232,10 @@ bool JdwpAdbState::Accept() {
PLOG(ERROR) << "Could not create ADB control socket";
return false;
}
+ struct timeval timeout;
+ timeout.tv_sec = kControlSockSendTimeout;
+ timeout.tv_usec = 0;
+ setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout));
{
MutexLock mu(Thread::Current(), state_lock_);
control_sock_ = sock;