mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-03-02 06:43:53 +08:00
athenad: reconnect after not receiving ping (#20974)
* athenad: reconnect after not receiving ping * make sidebar timeout longer than timeout in athena * whitespace
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user