fix(conn): 拔线后不再永远「已连接」
1) pollStatus 把 5s 超时 AbortError / HTTP 非 2xx 计入失败,走离线+清指标 2) DeviceLink 快照不得把本页已判离线改回在线(Owner 连败 3 次前会盖绿灯)
This commit is contained in:
@@ -17,7 +17,7 @@ import {
|
||||
import {
|
||||
scheduleStatusPoll, startPolling, pausePollingForUpload,
|
||||
resumePollingAfterUpload, pollStatus, pollLogs, setStatusPollIntervalMs
|
||||
} from './common/polling.js?v=20260916d';
|
||||
} from './common/polling.js?v=20260916e';
|
||||
|
||||
import {
|
||||
OtaSessionState, otaSessionState, otaSessionTarget, otaFailReason,
|
||||
|
||||
@@ -61,8 +61,10 @@ export function updateConnectionUi(connected, text) {
|
||||
try {
|
||||
var snap = deviceLink.getSnapshot();
|
||||
if (snap && snap.ts && (Date.now() - snap.ts) < 5000) {
|
||||
/* 只覆盖在线布尔,保留调用方语义文案(设备忙/诊断中/STA…) */
|
||||
connected = !!snap.links.esp32.online;
|
||||
/* Hub 可把在线压成离线;**不得**把本页刚判的离线改回在线。
|
||||
* Owner 要连失败 3 次才翻离线,期间若无脑覆盖,
|
||||
* OTA 页超时判离线后灯又会被点绿 → 拔线后永远「已连接」。 */
|
||||
if (!snap.links.esp32.online) connected = false;
|
||||
if (!text) text = connected ? '已连接' : '离线';
|
||||
}
|
||||
} catch (_) {}
|
||||
|
||||
@@ -237,12 +237,19 @@ export async function pollStatus() {
|
||||
if (window.isEsp32Rebooting) {
|
||||
window.applyRebootingRuntimeState();
|
||||
}
|
||||
} else {
|
||||
/* HTTP 非 2xx:设备在但不健康,也必须走失败路径,否则 UI 永远停在「已连接」 */
|
||||
var httpErr = new Error('HTTP ' + resp.status);
|
||||
httpErr.status = resp.status;
|
||||
throw httpErr;
|
||||
}
|
||||
clearTimeout(pollTimer);
|
||||
} catch (e) {
|
||||
clearTimeout(pollTimer);
|
||||
// 自身 AbortController 触发的取消不算失败,静默返回
|
||||
if (e && e.name === "AbortError") return;
|
||||
/* 5s 超时 abort:拔线后 TCP 常挂死到超时,不是「主动取消」。
|
||||
* 旧逻辑把所有 AbortError 静默 return → 拔掉后永远「已连接」。
|
||||
* 仅上传暂停导致的 abort 不算失败(pausePollingForUpload 已 abort 在途请求)。 */
|
||||
if (e && e.name === "AbortError" && window.pollingPausedForUpload) return;
|
||||
// 先判定 OTA 是否进行中:OTA 期间所有失败都不计入 consecutivePollFailures,
|
||||
// 也不触发诊断。避免"上传完成→finalize→重启"窗口期失败计数累积,
|
||||
// 切回 IDLE 瞬间立即触发 5-fail 诊断,干扰进度显示。
|
||||
|
||||
+1
-1
@@ -569,7 +569,7 @@
|
||||
必须持有租约,否则服务端在租约归零宽限期后会把循环又停掉。
|
||||
与 tabs.html / motor.html 并存时连接数>1,互不影响。 -->
|
||||
<script src="../js/common/app-lease.js"></script>
|
||||
<script type="module" src="../js/app.js?v=20260916d"></script>
|
||||
<script type="module" src="../js/app.js?v=20260916e"></script>
|
||||
<script type="module" src="../js/ota/console-mode.js?v=20260916d"></script>
|
||||
<script type="module" src="../js/ble_ota.js?v=20260901d"></script>
|
||||
<!-- 内联兜底:同步 BLE 按钮 data-ble-state 与 checkbox.checked
|
||||
|
||||
Reference in New Issue
Block a user