summaryrefslogtreecommitdiff
path: root/dt_fd_forward
diff options
context:
space:
mode:
author Alex Light <allight@google.com> 2021-02-01 19:25:35 -0800
committer Alex Light <allight@google.com> 2021-02-03 17:54:23 +0000
commitf51d182c3d797bd14bcc66a3c0bf1fc6f9adf8ee (patch)
tree12921f3bfd788a0dc2a8b5937ebf0ed13af220e5 /dt_fd_forward
parent3098e36d2935ad7ce9995ef5fb7395d035383047 (diff)
Fix DDMS-JDWP race
DDMS would race against the JDWP-Handshake in some circumstances causing clients to become confused as DDMS packets were recieved before the handshake reply. Test: atest CtsJdwpTunnelHostTestCases Test: ./tools/dt_fds_forward.py Bug: 178655046 Change-Id: Iabeb68829455ee4d2682f0a14591c8b7b0f4fc5f
Diffstat (limited to 'dt_fd_forward')
-rw-r--r--dt_fd_forward/dt_fd_forward.cc9
-rw-r--r--dt_fd_forward/export/fd_transport.h5
2 files changed, 14 insertions, 0 deletions
diff --git a/dt_fd_forward/dt_fd_forward.cc b/dt_fd_forward/dt_fd_forward.cc
index d5b6de5ead..2a6bfda0ad 100644
--- a/dt_fd_forward/dt_fd_forward.cc
+++ b/dt_fd_forward/dt_fd_forward.cc
@@ -52,6 +52,8 @@
#include <base/strlcpy.h>
+#include "fd_transport.h"
+
namespace dt_fd_forward {
// Helper that puts line-number in error message.
@@ -287,6 +289,11 @@ static void SendAcceptMessage(int fd) {
TEMP_FAILURE_RETRY(send(fd, kAcceptMessage, sizeof(kAcceptMessage), MSG_EOR));
}
+static void SendHandshakeCompleteMessage(int fd) {
+ TEMP_FAILURE_RETRY(
+ send(fd, kHandshakeCompleteMessage, sizeof(kHandshakeCompleteMessage), MSG_EOR));
+}
+
IOResult FdForwardTransport::ReceiveFdsFromSocket(bool* do_handshake) {
union {
cmsghdr cm;
@@ -402,6 +409,8 @@ jdwpTransportError FdForwardTransport::Accept() {
continue;
}
}
+ // Tell everyone we have finished the handshake.
+ SendHandshakeCompleteMessage(close_notify_fd_);
break;
}
CHECK(ChangeState(TransportState::kOpening, TransportState::kOpen));
diff --git a/dt_fd_forward/export/fd_transport.h b/dt_fd_forward/export/fd_transport.h
index 144ac5c6ec..40dbe42470 100644
--- a/dt_fd_forward/export/fd_transport.h
+++ b/dt_fd_forward/export/fd_transport.h
@@ -65,6 +65,11 @@ static constexpr char kListenEndMessage[] = "dt_fd_forward:END-LISTEN";
// fds are closed.
static constexpr char kAcceptMessage[] = "dt_fd_forward:ACCEPTED";
+// This message is sent over the fd associated with the transport when we have
+// completed the handshake. If the handshake was already performed this is sent
+// immediately.
+static constexpr char kHandshakeCompleteMessage[] = "dt_fd_forward:HANDSHAKE-COMPLETE";
+
// This message is sent over the fd associated with the transport when we are closing the fds. This
// can be used by the proxy to send additional data on a dup'd fd. The write_lock_fd_ will be held
// until the other two fds are closed and then it will be released and closed.