fix: adb 命令超时 + STF 释放失败检查,杜绝设备卡死/占用悬空
- adb 所有命令加 30s 超时:connect 到不可达地址不再无限挂起(worker 不再卡 connecting) - STF release 检查响应状态并重试:504 等失败不再被静默吞掉,释放失败会真实上报 - release_all_mine 返回 (released, failed);web /api/release 透出失败列表
This commit is contained in:
+12
-8
@@ -51,13 +51,17 @@ class STFDevice:
|
||||
raise STFError(f"占用设备失败: {msg}", "conflict")
|
||||
_log.info(f"[{self.serial}] STF 占用成功")
|
||||
|
||||
# 优先直连设备 serial(当 serial 本身就是 IP:5555 时,如 Tailscale 网络)
|
||||
# 这比 STF remoteConnect 桥接更稳定,避免桥接地址认证失败
|
||||
# 直连优先:serial 本身是 IP:5555(如 Tailscale 网络设备)时直接 adb connect。
|
||||
# 实测(本机 100.100.10.2,设备 100.100.10.x):
|
||||
# - 本机在 tailnet 内时直连可靠且快(<1s),且只 connect、绝不 disconnect/kill-server,
|
||||
# 不会影响 STF provider 共享的 adb 连接(STF 端设备保持 present/ready)。
|
||||
# - STF remoteConnect 桥接在此环境反而有 adb key 认证问题(隧道显示 unauthorized,
|
||||
# 即使设备已授权本机 key),直连才是可靠路径。
|
||||
# 仅当 serial 不是 IP:port(如 USB 序列号)时才走 STF 桥接。
|
||||
if ":" in self.serial:
|
||||
self.remote_adb_url = self.serial
|
||||
_log.info(f"[{self.serial}] 直连设备: {self.remote_adb_url}")
|
||||
else:
|
||||
# serial 不是 IP:port 格式,走 STF remoteConnect 桥接
|
||||
self.remote_adb_url = self.stf.remote_connect(self.serial)
|
||||
_log.info(f"[{self.serial}] STF 桥接: {self.remote_adb_url}")
|
||||
|
||||
@@ -75,18 +79,18 @@ class STFDevice:
|
||||
if not self.serial:
|
||||
return
|
||||
# 直连模式(remote_adb_url == serial):不 disconnect
|
||||
# STF agent 可能共享同一个 adb 连接,disconnect 会导致 STF 设备离线后重新连接
|
||||
# STF provider 共享该 IP:5555 的 adb transport,disconnect 会让 STF 误判离线并重连
|
||||
if self.remote_adb_url and self.remote_adb_url != self.serial:
|
||||
adb_disconnect(self.remote_adb_url)
|
||||
try:
|
||||
self.stf.remote_disconnect(self.serial)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
self.stf.release(self.serial)
|
||||
ok, msg = self.stf.release(self.serial)
|
||||
if ok:
|
||||
_log.info(f"[{self.serial}] 已释放")
|
||||
except Exception as e:
|
||||
_log.warning(f"[{self.serial}] 释放失败: {e}")
|
||||
else:
|
||||
_log.warning(f"[{self.serial}] STF 释放失败: {msg}")
|
||||
|
||||
|
||||
# ================== 全局 worker 状态注册表(供 web_server 读取) ==================
|
||||
|
||||
Reference in New Issue
Block a user