Skip to content

Commit 07969f0

Browse files
author
Felix Exner (fexner)
authored
dashboard_client: Allow a larger timeout on initial connection (#126)
Apparently, if we connect to the socket right after it became available, it can happen, that we don't get a "connected" message from the dashboard server in a second. This commit should not only increase the timeout on the initial read to a value that should be sufficient, but also establishes a retry with a warning output.
1 parent 0bc57de commit 07969f0

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/ur/dashboard_client.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,31 @@ bool DashboardClient::connect()
4545
return false;
4646
}
4747
bool ret_val = false;
48-
if (TCPSocket::setup(host_, port_))
48+
49+
timeval tv;
50+
51+
while (not ret_val)
4952
{
50-
URCL_LOG_INFO("%s", read().c_str());
51-
ret_val = true;
53+
// The first read after connection can take more time.
54+
tv.tv_sec = 10;
55+
tv.tv_usec = 0;
56+
TCPSocket::setReceiveTimeout(tv);
57+
try
58+
{
59+
if (TCPSocket::setup(host_, port_))
60+
{
61+
URCL_LOG_INFO("%s", read().c_str());
62+
ret_val = true;
63+
}
64+
}
65+
catch (TimeoutException)
66+
{
67+
URCL_LOG_WARN("Did not receive dashboard bootup message although connection was established. This should not "
68+
"happen, please contact the package maintainers. Retrying anyway...");
69+
}
5270
}
5371

54-
timeval tv;
72+
// Reset read timeout to "normal" socket timeout
5573
tv.tv_sec = 1;
5674
tv.tv_usec = 0;
5775
TCPSocket::setReceiveTimeout(tv);

0 commit comments

Comments
 (0)