From f923f47b98266f616de937db5597e5844c822dab Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Thu, 20 May 2021 13:57:46 +0200 Subject: [PATCH] athenad: reconnect after not receiving ping (#20974) * athenad: reconnect after not receiving ping * make sidebar timeout longer than timeout in athena * whitespace old-commit-hash: f9f84fe8a2540dd87b05d93cb8234707d8bbe21b --- selfdrive/athena/athenad.py | 10 ++++++++-- selfdrive/ui/qt/sidebar.cc | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/selfdrive/athena/athenad.py b/selfdrive/athena/athenad.py index 5a299e475d..4e5483aecf 100755 --- a/selfdrive/athena/athenad.py +++ b/selfdrive/athena/athenad.py @@ -38,6 +38,7 @@ LOCAL_PORT_WHITELIST = set([8022]) LOG_ATTR_NAME = 'user.upload' LOG_ATTR_VALUE_MAX_UNIX_TIME = int.to_bytes(2147483647, 4, sys.byteorder) +RECONNECT_TIMEOUT_S = 70 dispatcher["echo"] = lambda s: s recv_queue: Any = queue.Queue() @@ -385,6 +386,7 @@ def ws_proxy_send(ws, local_sock, signal_sock, end_event): def ws_recv(ws, end_event): + last_ping = int(sec_since_boot() * 1e9) while not end_event.is_set(): try: opcode, data = ws.recv_data(control_frame=True) @@ -393,9 +395,13 @@ def ws_recv(ws, end_event): data = data.decode("utf-8") recv_queue.put_nowait(data) elif opcode == ABNF.OPCODE_PING: - Params().put("LastAthenaPingTime", str(int(sec_since_boot() * 1e9))) + last_ping = int(sec_since_boot() * 1e9) + Params().put("LastAthenaPingTime", str(last_ping)) except WebSocketTimeoutException: - pass + ns_since_last_ping = int(sec_since_boot() * 1e9) - last_ping + if ns_since_last_ping > RECONNECT_TIMEOUT_S * 1e9: + cloudlog.exception("athenad.wc_recv.timeout") + end_event.set() except Exception: cloudlog.exception("athenad.ws_recv.exception") end_event.set() diff --git a/selfdrive/ui/qt/sidebar.cc b/selfdrive/ui/qt/sidebar.cc index b55ea90fe3..8c49fbf396 100644 --- a/selfdrive/ui/qt/sidebar.cc +++ b/selfdrive/ui/qt/sidebar.cc @@ -54,7 +54,7 @@ void Sidebar::update(const UIState &s) { connect_status = warning_color; auto last_ping = params.get("LastAthenaPingTime"); if (last_ping) { - bool online = nanos_since_boot() - *last_ping < 70e9; + bool online = nanos_since_boot() - *last_ping < 80e9; connect_str = online ? "ONLINE" : "ERROR"; connect_status = online ? good_color : danger_color; }