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: f9f84fe8a2
commatwo_master
Willem Melching 4 years ago committed by GitHub
parent 89105c46ac
commit f923f47b98
  1. 10
      selfdrive/athena/athenad.py
  2. 2
      selfdrive/ui/qt/sidebar.cc

@ -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()

@ -54,7 +54,7 @@ void Sidebar::update(const UIState &s) {
connect_status = warning_color;
auto last_ping = params.get<float>("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;
}

Loading…
Cancel
Save