From 0574704d774870e8357fb820d5ef71e75164e13c Mon Sep 17 00:00:00 2001 From: RSAP <46652797+DABodr@users.noreply.github.com> Date: Tue, 4 Aug 2026 20:30:31 +0200 Subject: [PATCH 01/15] Retry transient telemetry timeouts --- FMScanMonitor/CHANGELOG.md | 6 +++++ FMScanMonitor/README.md | 4 +-- FMScanMonitor/fm-scan-monitor-engine.js | 17 ++++++++++++ FMScanMonitor/fm-scan-monitor-engine.test.js | 25 +++++++++++++++++ FMScanMonitor/fm-scan-monitor.js | 10 +++---- FMScanMonitor/fm-scan-monitor_server.js | 28 +++++++++++++++++--- FMScanMonitorPlugin.js | 2 +- INSTALLATION.md | 2 +- README.md | 6 ++--- 9 files changed, 84 insertions(+), 16 deletions(-) diff --git a/FMScanMonitor/CHANGELOG.md b/FMScanMonitor/CHANGELOG.md index b639bb2..f12c8f2 100644 --- a/FMScanMonitor/CHANGELOG.md +++ b/FMScanMonitor/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 0.9.9 + +- Retry the internal telemetry request up to three times when the Webserver event loop is temporarily busy. +- Keep a single transient `/api` delay from stopping a continuous scan and leaving a permanent error status. +- Report the attempt count only when all recovery attempts fail. + ## 0.9.8 - Limit simultaneous OpenTopoMap downloads, with a stricter three-request limit on iPhone and iPad. diff --git a/FMScanMonitor/README.md b/FMScanMonitor/README.md index c8426c6..d71775e 100644 --- a/FMScanMonitor/README.md +++ b/FMScanMonitor/README.md @@ -2,7 +2,7 @@ **FM Scan Monitor by Aurel** is a responsive live band scanner and reception monitor for FM-DX Webserver, designed for both desktop and mobile browsers. It is a standalone plugin and does not modify the Webserver core or the existing Scanner plugin. -## Version 0.9.8 +## Version 0.9.9 - Single-pass and continuous scanning. - Password-free public tuner handover: a visitor can explicitly pause an active scan, use the normal tuner controls or tune directly from any received-station card, and release them without gaining scanner administration rights. @@ -67,7 +67,7 @@ The report is generated locally and displayed directly in the browser's native P ## Installation -Copy `FMScanMonitorPlugin.js` and the complete `FMScanMonitor` directory into the Webserver `plugins` directory. Restart FM-DX Webserver, open Administration > Plugins, enable **FM Scan Monitor by Aurel [v0.9.8]**, save, restart once more when enabling it for the first time, and reload the receiver page while logged in as administrator. +Copy `FMScanMonitorPlugin.js` and the complete `FMScanMonitor` directory into the Webserver `plugins` directory. Restart FM-DX Webserver, open Administration > Plugins, enable **FM Scan Monitor by Aurel [v0.9.9]**, save, restart once more when enabling it for the first time, and reload the receiver page while logged in as administrator. Upgrading from an earlier `FMScanMobile` release automatically copies the existing browser settings, hidden-frequency rules, distance filter and temporary public-control state to the new `fmScanMonitor` storage keys. The legacy values are retained as a safe fallback. diff --git a/FMScanMonitor/fm-scan-monitor-engine.js b/FMScanMonitor/fm-scan-monitor-engine.js index 86b0714..b838f5c 100644 --- a/FMScanMonitor/fm-scan-monitor-engine.js +++ b/FMScanMonitor/fm-scan-monitor-engine.js @@ -35,6 +35,22 @@ function sleep(milliseconds) { return new Promise(resolve => setTimeout(resolve, milliseconds)); } +async function retryAsync(operation, { attempts = 3, delayMs = 250 } = {}) { + if (typeof operation !== 'function') throw new TypeError('A retry operation is required.'); + const maximumAttempts = Math.max(1, Math.trunc(Number(attempts) || 1)); + const retryDelay = Math.max(0, Number(delayMs) || 0); + let lastError = null; + for (let attempt = 1; attempt <= maximumAttempts; attempt += 1) { + try { + return await operation(attempt); + } catch (error) { + lastError = error instanceof Error ? error : new Error(String(error)); + if (attempt < maximumAttempts && retryDelay > 0) await sleep(retryDelay); + } + } + throw lastError; +} + function normalizePi(value) { const pi = String(value ?? '').trim().toUpperCase(); return /^[0-9A-F]{4}$/.test(pi) && pi !== '0000' ? pi : ''; @@ -588,5 +604,6 @@ module.exports = { normalizeTransmitterCountry, parsePsErrors, publicTuneAccessMode, + retryAsync, sanitizeSettings }; diff --git a/FMScanMonitor/fm-scan-monitor-engine.test.js b/FMScanMonitor/fm-scan-monitor-engine.test.js index 09abb12..1c96011 100644 --- a/FMScanMonitor/fm-scan-monitor-engine.test.js +++ b/FMScanMonitor/fm-scan-monitor-engine.test.js @@ -8,9 +8,34 @@ const { normalizeTelemetry, normalizeTransmitterCountry, publicTuneAccessMode, + retryAsync, sanitizeSettings } = require('./fm-scan-monitor-engine'); +test('retries a transient telemetry operation and returns the recovered value', async () => { + let calls = 0; + const value = await retryAsync(async attempt => { + calls += 1; + if (attempt < 3) throw new Error('temporary telemetry delay'); + return { frequency: 100.9 }; + }, { attempts: 3, delayMs: 0 }); + + assert.deepEqual(value, { frequency: 100.9 }); + assert.equal(calls, 3); +}); + +test('preserves the last telemetry error after all retry attempts fail', async () => { + let calls = 0; + await assert.rejects( + retryAsync(async () => { + calls += 1; + throw new Error(`failure ${calls}`); + }, { attempts: 3, delayMs: 0 }), + /failure 3/ + ); + assert.equal(calls, 3); +}); + test('sanitizes the shared LOC and DX distance thresholds', () => { const configured = sanitizeSettings({ localDistanceKm: 15, dxDistanceKm: 250 }); assert.equal(configured.localDistanceKm, 15); diff --git a/FMScanMonitor/fm-scan-monitor.js b/FMScanMonitor/fm-scan-monitor.js index 4e3c3c4..031ab83 100644 --- a/FMScanMonitor/fm-scan-monitor.js +++ b/FMScanMonitor/fm-scan-monitor.js @@ -251,7 +251,7 @@ const link = document.createElement('link'); link.id = `${PLUGIN_ID}-styles`; link.rel = 'stylesheet'; - link.href = 'js/plugins/FMScanMonitor/fm-scan-monitor.css?v=0.9.8'; + link.href = 'js/plugins/FMScanMonitor/fm-scan-monitor.css?v=0.9.9'; document.head.appendChild(link); } @@ -320,12 +320,12 @@ return; } root.innerHTML = ` -