src.nth.io/

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Hoersten <[email protected]>2026-06-21 10:56:49 -0500
committerLuke Hoersten <[email protected]>2026-06-21 10:56:49 -0500
commit356e637b412bd8bcbbc83afa768cf7b00fabd67f (patch)
tree2b5ff9b9e81924f05078cf882ee2f7e5db2ad312
parent7ce51d61f0b7537002c5b0d415cac67391a2b235 (diff)
scrypted: retry once on Settings-page /state /config fetch failure
The Settings 'Status (live)' section reaches the device via two sequential GETs. A transient socket-level failure (httpd worker pool briefly saturated by the active stream connection, mid-reboot window, network jitter) used to leave the page showing 'device: offline / unreachable (fetch failed)' even though the device was fine — a refresh would clear it. One automatic 250 ms-backoff retry on either GET removes the sporadic false positive. The 3 s per-request timeout stays the same, so the worst-case page latency on a genuinely offline device is ~6.5 s (3 + 0.25 + 3) instead of 3 s — acceptable for a deliberate Settings open.
-rw-r--r--scrypted/scrypted-viewport.ts27
1 files changed, 23 insertions, 4 deletions
diff --git a/scrypted/scrypted-viewport.ts b/scrypted/scrypted-viewport.ts
index d4f0b55..0345c1d 100644
--- a/scrypted/scrypted-viewport.ts
+++ b/scrypted/scrypted-viewport.ts
@@ -239,12 +239,31 @@ class Viewport extends ScryptedDeviceBase implements Settings {
// in-flight stream-socket cap-flush reconnect). 3s timeout is
// generous but not so long that an offline device feels
// unresponsive in the UI.
+ //
+ // One automatic retry on failure: "fetch failed" at the socket
+ // level usually means the firmware's httpd worker pool was
+ // briefly saturated (the stream connection plus an /state poll
+ // can starve a third request on max_open_sockets=2). A 250 ms
+ // pause then try again before giving up — eliminates the
+ // sporadic "offline / unreachable" the Settings page would
+ // otherwise show during normal streaming.
+ const fetchJsonRetry = async (url: string): Promise<any> => {
+ let lastErr: any;
+ for (let attempt = 0; attempt < 2; attempt++) {
+ try {
+ const r = await fetch(url, { signal: AbortSignal.timeout(3000) });
+ return await r.json();
+ } catch (e) {
+ lastErr = e;
+ if (attempt === 0) await new Promise(res => setTimeout(res, 250));
+ }
+ }
+ throw lastErr;
+ };
if (this.host) {
try {
- const stateRes = await fetch(`http://${this.host}/state`,
- { signal: AbortSignal.timeout(3000) }).then(r => r.json());
- const configRes = await fetch(`http://${this.host}/config`,
- { signal: AbortSignal.timeout(3000) }).then(r => r.json());
+ const stateRes = await fetchJsonRetry(`http://${this.host}/state`);
+ const configRes = await fetchJsonRetry(`http://${this.host}/config`);
settings.push(
{ group: "Status (live)", key: "_st_name", title: "name", value: stateRes.name, readonly: true } as any,
{ group: "Status (live)", key: "_st_mac", title: "mac", value: stateRes.mac, readonly: true } as any,