Retries connection until established.
I believe what's currently causing tombstones is adbd not coming up fast
enough for the socket_forward_proxy. This is not the ultimate solution,
but it is a short-term solution for the current problem.
Bug: 75465725
Change-Id: Ifbcf6c8f200e7e272c8cfc5785f86149c40fef98
diff --git a/common/frontend/socket_forward_proxy/Android.bp b/common/frontend/socket_forward_proxy/Android.bp
index 1ffec39..c70983e 100644
--- a/common/frontend/socket_forward_proxy/Android.bp
+++ b/common/frontend/socket_forward_proxy/Android.bp
@@ -21,6 +21,7 @@
shared_libs: [
"libbase",
"libcuttlefish_fs",
+ "cuttlefish_auto_resources",
"vsoc_lib",
"liblog",
],
diff --git a/common/frontend/socket_forward_proxy/main.cpp b/common/frontend/socket_forward_proxy/main.cpp
index 6022d41..7a064c4 100644
--- a/common/frontend/socket_forward_proxy/main.cpp
+++ b/common/frontend/socket_forward_proxy/main.cpp
@@ -193,15 +193,25 @@
}
#else
+cvd::SharedFD OpenSocketConnection(int port) {
+ while (true) {
+ auto sock = cvd::SharedFD::SocketLocalClient(port, SOCK_STREAM);
+ if (sock->IsOpen()) {
+ return sock;
+ }
+ LOG(WARNING) << "could not connect on port " << port
+ << ". sleeping for 1 second";
+ sleep(1);
+ }
+}
+
[[noreturn]] void guest(SocketForwardRegionView* shm) {
LOG(INFO) << "Starting guest mainloop";
while (true) {
auto conn = shm->AcceptConnection();
LOG(INFO) << "shm connection accepted";
- auto sock =
- cvd::SharedFD::SocketLocalClient(conn.first.port(), SOCK_STREAM);
- CHECK(sock->IsOpen()) << "Could not open socket to port "
- << conn.first.port();
+ auto sock = OpenSocketConnection(conn.first.port());
+ CHECK(sock->IsOpen());
LOG(INFO) << "socket opened to " << conn.first.port();
LaunchWorkers(std::move(conn), std::move(sock));
}