fix(decoder): connect even when the browser storage is full
A big installation outgrew the localStorage quota; saveState() threw QuotaExceededError and, since connecting saves first, the decoder never came online. The local copy is only a cache of the server state, so a write that doesn't fit now drops it instead of throwing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c8a797fe6f
commit
2c6c37f6ca
9 files changed
+99
-4
No files matched your search
@@ -8,6 +8,12 @@ The application version is maintained in `package.json` and displayed in the adm
|
||||
|
||||
No changes recorded yet.
|
||||
|
||||
## 1.41.1 - 2026-10-18
|
||||
|
||||
### Fixed
|
||||
|
||||
- **Decoder would not connect on a big installation.** The browser's local copy of the state outgrew the storage quota (about 5 MB: results, training stats, logo). Every save then failed with `QuotaExceededError`, and since connecting saves first, the decoder never came online and Race Day showed "Decoder offline" although AMMC was running. The local copy is only a cache of the server's state: when it doesn't fit it is dropped, and saving to the server and connecting carry on.
|
||||
|
||||
## 1.41.0 - 2026-10-17
|
||||
|
||||
### Changed
|
||||
|
||||
@@ -967,6 +967,15 @@ Reported by the user: non-technical club members found it too hard to start a ne
|
||||
|
||||
Verified: 266 unit tests and 80 browser scenarios pass, including `tests/browser_race_day_quick.js` (Dashboard Start practice creates, starts and opens a practice on Race Day; the quick layout moves it; the picker switches session; Timing has no run controls). `tests/browser_race_day.js` now checks that buttons are shown only when they apply. Video frames checked: count-down, To 10 s, then Pause/Finish once the heat runs.
|
||||
|
||||
### Follow-up: decoder offline from a full browser storage (2026-10-18)
|
||||
|
||||
The decoder kept showing offline on the club PC although AMMC on 9443 was reachable (TCP from the PC, a `101 Switching Protocols` handshake from the server) and served other clients. The browser console showed `QuotaExceededError` on `localStorage.setItem("rc_timing_control_v1")` in `saveState()`, called by `connectDecoderHelper` before it opens the socket - so every Connect and the startup connect aborted. The diagnostic log only ever showed `disconnected`, never `connecting`.
|
||||
|
||||
- [x] `src/local_cache.js` `writeLocalCache()`: never throws; on failure it removes the stale cache (no partial copy, which could be synced back over the server state).
|
||||
- [x] `saveState()` uses it and warns once in the console.
|
||||
|
||||
Verified: unit tests in `tests/local_cache.test.js`; `tests/browser_decoder_url.js` makes the state key throw `QuotaExceededError` and checks that Connect still reaches a fake decoder, the URL is saved to the server and the local copy is dropped. It fails without the fix ("Timed out: connects although the browser storage is full"). 269 unit and 81 browser scenarios pass.
|
||||
|
||||
## Documentation maintenance
|
||||
|
||||
- [x] Update the architecture's module/dependency inventory as modules change.
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "rc-racecore",
|
||||
"version": "1.41.0",
|
||||
"version": "1.41.1",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "rc-racecore",
|
||||
"version": "1.41.0",
|
||||
"version": "1.41.1",
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"better-sqlite3": "^12.11.1",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "rc-racecore",
|
||||
"version": "1.41.0",
|
||||
"version": "1.41.1",
|
||||
"private": true,
|
||||
"description": "RC RaceCore live timing and race control with AMMC ingest and SQLite persistence",
|
||||
"engines": {
|
||||
|
||||
+5
-1
@@ -30,6 +30,7 @@ import { renderEventManagerMarkup } from "./event_manager_view.js";
|
||||
import { renderEventManagerView } from "./event_manager_controller.js";
|
||||
import { createDefaultAmmcConfigHelper, getManagedWsUrlHelper, loadAmmcConfigFromBackendHelper, saveAmmcConfigToBackendHelper, refreshAmmcStatusHelper, startManagedAmmcHelper, stopManagedAmmcHelper, applyPersistedStateHelper, hydrateFromBackendHelper, scheduleBackendSyncHelper, syncStateToBackendHelper, pingBackendHelper, checkAppVersionHelper, startAppVersionPollingHelper, startOverlaySyncHelper, startBackgroundHydrationHelper, startOverlayRotationHelper, startOverlayLiveRefreshHelper, ensureAudioContextHelper, playPassingBeepHelper, playFinishSirenHelper, playLeaderCueHelper, playStartCueHelper, playBestLapCueHelper, pushOverlayEventHelper, getSpeechVoicesHelper, speakTextHelper, announceRaceStartedHelper, announceRaceFinishedHelper, handleSessionTimerTickHelper, tickClockHelper } from "./runtime_services.js";
|
||||
import { connectDecoderHelper, disconnectDecoderHelper, processDecoderMessageHelper } from "./decoder_runtime.js";
|
||||
import { writeLocalCache } from "./local_cache.js";
|
||||
import { normalizeTrainingState as normalizeTrainingStateLogic, syncTrainingLedger as syncTrainingLedgerLogic, buildDriverTrainingStats as buildDriverTrainingStatsLogic, buildDriverTimingChannelStats as buildDriverTimingChannelStatsLogic, buildDriverActivePracticeStats as buildDriverActivePracticeStatsLogic, buildEvenLapsProgress as buildEvenLapsProgressLogic, buildStepTrainingProgress as buildStepTrainingProgressLogic, buildTrainingRecommendation as buildTrainingRecommendationLogic, getTrainingGoalProgress as getTrainingGoalProgressLogic, getNextTrainingMilestone as getNextTrainingMilestoneLogic, buildTrainingMissions as buildTrainingMissionsLogic, buildTrainingHighlights as buildTrainingHighlightsLogic, getClubTrainingGoalProgress as getClubTrainingGoalProgressLogic, countDriverExerciseSessions as countDriverExerciseSessionsLogic, countExerciseSessions as countExerciseSessionsLogic, buildTrainingPaceBuckets as buildTrainingPaceBucketsLogic, buildTrainingWeekdayStats as buildTrainingWeekdayStatsLogic, buildTrainingStintAnalysis as buildTrainingStintAnalysisLogic, buildTrainingMarkerComparisons as buildTrainingMarkerComparisonsLogic } from "./training_logic.js";
|
||||
import { renderTrainingView } from "./training_views.js";
|
||||
import { renderResultsArchiveView } from "./results_archive_view.js";
|
||||
@@ -757,6 +758,7 @@ function getSessionTypeChoices(mode) {
|
||||
return mode === "track" ? SESSION_TYPES.filter((type) => type !== "team_race") : SESSION_TYPES;
|
||||
}
|
||||
const STORAGE_KEY = "rc_timing_control_v1";
|
||||
let localCacheFull = false;
|
||||
const DEFAULT_LANGUAGE = "sv";
|
||||
const DEFAULT_THEME = "dark";
|
||||
const AVAILABLE_THEMES = ["dark", "nord", "light"];
|
||||
@@ -5079,7 +5081,9 @@ function loadState() {
|
||||
|
||||
function saveState(options = {}) {
|
||||
const persistable = buildPersistableState();
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(persistable));
|
||||
const cached = writeLocalCache(localStorage, STORAGE_KEY, persistable);
|
||||
if (!cached.ok && !localCacheFull) console.warn("Browser storage is full; the local cache is dropped and the server's state is used.", cached.error);
|
||||
localCacheFull = !cached.ok;
|
||||
if (!options.skipBackend) {
|
||||
localStateVersion += 1;
|
||||
localStateDirty = true;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// The browser's localStorage copy of the state is only a cache: the server's SQLite state is the
|
||||
// truth and every page load hydrates from it. A big installation (results, training ledger, logo)
|
||||
// outgrows the ~5 MB quota, and setItem then throws - which used to abort whatever called
|
||||
// saveState(), e.g. connecting the decoder. A cache that can't be written is dropped instead
|
||||
// (the page then starts from the server like a fresh browser); a cut-down copy is never kept,
|
||||
// since a partial state could be synced back over the server's.
|
||||
export function writeLocalCache(storage, key, value) {
|
||||
try {
|
||||
storage.setItem(key, JSON.stringify(value));
|
||||
return { ok: true };
|
||||
} catch (error) {
|
||||
try { storage.removeItem(key); } catch {}
|
||||
return { ok: false, error };
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,31 @@ export async function runDecoderUrlSmoke({ evaluate, navigate, savedState, waitF
|
||||
} finally {
|
||||
await second.close();
|
||||
}
|
||||
|
||||
// A full browser storage (big installation: results, training ledger, logo) made every
|
||||
// saveState() throw QuotaExceededError - and Connect saves before it connects, so the
|
||||
// decoder never came online. The local copy is only a cache of the server state.
|
||||
const third = await startFakeDecoder();
|
||||
try {
|
||||
const thirdUrl = `ws://127.0.0.1:${third.port}`;
|
||||
await evaluate(`(() => {
|
||||
window.__realSetItem = Storage.prototype.setItem;
|
||||
Storage.prototype.setItem = function (key, value) {
|
||||
if (key === "rc_timing_control_v1") throw new DOMException("Setting the value of '" + key + "' exceeded the quota.", "QuotaExceededError");
|
||||
return window.__realSetItem.call(this, key, value);
|
||||
};
|
||||
const input = document.querySelector('#settingsForm [name="wsUrl"]');
|
||||
input.value = ${JSON.stringify(thirdUrl)};
|
||||
document.getElementById("settingsConnect").click();
|
||||
})()`);
|
||||
await waitFor(async () => third.totalConnections() > 0, "connects although the browser storage is full");
|
||||
await waitFor(async () => (await savedState()).settings.wsUrl === thirdUrl, "and still saves to the server");
|
||||
assert.equal(await evaluate(`localStorage.getItem("rc_timing_control_v1")`), null, "the stale local copy is dropped");
|
||||
console.log("PASS a full browser storage no longer stops the decoder from connecting or saving to the server");
|
||||
} finally {
|
||||
await evaluate(`window.__realSetItem && (Storage.prototype.setItem = window.__realSetItem)`);
|
||||
await third.close();
|
||||
}
|
||||
} finally {
|
||||
const current = await savedState();
|
||||
await fetch(base + "/api/state", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ ...current, settings: { ...current.settings, wsUrl: before.settings.wsUrl, autoReconnect: false } }) });
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { writeLocalCache } from "../src/local_cache.js";
|
||||
|
||||
function fakeStorage({ quota = Infinity } = {}) {
|
||||
const items = new Map();
|
||||
return {
|
||||
items,
|
||||
setItem(key, value) {
|
||||
if (String(value).length > quota) throw Object.assign(new Error("Setting the value exceeded the quota."), { name: "QuotaExceededError" });
|
||||
items.set(key, String(value));
|
||||
},
|
||||
removeItem(key) { items.delete(key); },
|
||||
};
|
||||
}
|
||||
|
||||
test("writes the state when it fits", () => {
|
||||
const storage = fakeStorage();
|
||||
assert.deepEqual(writeLocalCache(storage, "k", { a: 1 }), { ok: true });
|
||||
assert.equal(storage.items.get("k"), '{"a":1}');
|
||||
});
|
||||
|
||||
test("a full storage never throws and drops the stale cache instead of keeping an old copy", () => {
|
||||
const storage = fakeStorage({ quota: 20 });
|
||||
writeLocalCache(storage, "k", { a: 1 });
|
||||
const result = writeLocalCache(storage, "k", { results: "x".repeat(100) });
|
||||
assert.equal(result.ok, false);
|
||||
assert.equal(result.error.name, "QuotaExceededError");
|
||||
assert.equal(storage.items.has("k"), false, "the outdated copy is removed so a reload hydrates from the server");
|
||||
});
|
||||
|
||||
test("a storage that throws on remove too is still survived", () => {
|
||||
const storage = { setItem() { throw new Error("blocked"); }, removeItem() { throw new Error("blocked"); } };
|
||||
assert.equal(writeLocalCache(storage, "k", {}).ok, false);
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import "./auth.test.js";
|
||||
import "./local_cache.test.js";
|
||||
import "./prologue_logic.test.js";
|
||||
import "./suspect_laps_logic.test.js";
|
||||
import "./series_logic.test.js";
|
||||
|
||||
Reference in new issue
Block a user