fix(sync): retry failed saves every 5 s; restart the decoder simulator with the server (1.65.5)
This commit is contained in:
1 parent
fed83ddf67
commit
54f4c3b923
7 files changed
+44
-6
No files matched your search
@@ -8,6 +8,14 @@ The application version is maintained in `package.json` and displayed in the adm
|
|||||||
|
|
||||||
No changes recorded yet.
|
No changes recorded yet.
|
||||||
|
|
||||||
|
## 1.65.5 - 2026-11-05
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- A save that failed (e.g. while the server restarted) was only tried again at the next change or on "Try again", so "Changes waiting to save" could hang. Failed saves are now tried again every 5 s until they get through.
|
||||||
|
- The decoder simulator runs inside the server, so `npm restart` stopped it and the app was left pointing at nothing. The server now starts it again on boot when it was on (with the same lap time and spread).
|
||||||
|
- Stopping the simulator after it had been stopped and started again left the decoder address on the simulator; it now falls back to ws://127.0.0.1:9000 when the real address is unknown.
|
||||||
|
|
||||||
## 1.65.4 - 2026-11-05
|
## 1.65.4 - 2026-11-05
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "rc-racecore",
|
"name": "rc-racecore",
|
||||||
"version": "1.65.4",
|
"version": "1.65.5",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "rc-racecore",
|
"name": "rc-racecore",
|
||||||
"version": "1.65.4",
|
"version": "1.65.5",
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"better-sqlite3": "^12.11.1",
|
"better-sqlite3": "^12.11.1",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "rc-racecore",
|
"name": "rc-racecore",
|
||||||
"version": "1.65.4",
|
"version": "1.65.5",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "RC RaceCore live timing and race control with AMMC ingest and SQLite persistence",
|
"description": "RC RaceCore live timing and race control with AMMC ingest and SQLite persistence",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
@@ -773,7 +773,22 @@ app.use((_req, res) => {
|
|||||||
res.sendFile(path.join(__dirname, "index.html"));
|
res.sendFile(path.join(__dirname, "index.html"));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// The simulator was on before a restart (Settings keep the real decoder address while it is):
|
||||||
|
// start it again so the app finds it.
|
||||||
|
function restartDecoderSimIfOn() {
|
||||||
|
try {
|
||||||
|
const row = db.prepare("SELECT state_json FROM app_state WHERE id = 1").get();
|
||||||
|
const settings = row ? JSON.parse(row.state_json)?.settings : null;
|
||||||
|
if (!settings?.simPreviousWsUrl && !/:9099\/?$/.test(String(settings?.wsUrl || ""))) return;
|
||||||
|
decoderSim.start({ port: 9099, host: HOST, lapSec: settings.simLapSec || 18, spreadSec: settings.simSpreadSec ?? 1.5 })
|
||||||
|
.catch((error) => console.error(`Decoder simulator could not start again: ${error.message}`));
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Decoder simulator check failed: ${error.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
app.listen(PORT, HOST, () => {
|
app.listen(PORT, HOST, () => {
|
||||||
|
restartDecoderSimIfOn();
|
||||||
writePidFile();
|
writePidFile();
|
||||||
console.log(`RC Timing server listening on http://${HOST}:${PORT}`);
|
console.log(`RC Timing server listening on http://${HOST}:${PORT}`);
|
||||||
const lanUrls = getLanUrls(PORT);
|
const lanUrls = getLanUrls(PORT);
|
||||||
|
|||||||
+9
-1
@@ -166,7 +166,15 @@ const hydrateFromBackend = ({ initial = false } = {}) => hydrateFromBackendHelpe
|
|||||||
const isRunningRaceHere = () => !overlayMode && Boolean(getPrologueSession() || pendingStartSessionId || startsInProgress > 0
|
const isRunningRaceHere = () => !overlayMode && Boolean(getPrologueSession() || pendingStartSessionId || startsInProgress > 0
|
||||||
|| (state.decoder?.connected && state.sessions.some((session) => ["running", "paused"].includes(session.status))));
|
|| (state.decoder?.connected && state.sessions.some((session) => ["running", "paused"].includes(session.status))));
|
||||||
const scheduleBackendSync = () => scheduleBackendSyncHelper({ getBackendSyncTimer: () => backendSyncTimer, setBackendSyncTimer: (value) => { backendSyncTimer = value; }, syncStateToBackend });
|
const scheduleBackendSync = () => scheduleBackendSyncHelper({ getBackendSyncTimer: () => backendSyncTimer, setBackendSyncTimer: (value) => { backendSyncTimer = value; }, syncStateToBackend });
|
||||||
const syncStateToBackend = () => syncStateToBackendHelper({ backend, t, getBackendUrl, buildPersistableState, getLocalStateVersion: () => localStateVersion, getSyncedStateVersion: () => syncedStateVersion, setSyncedStateVersion: (value) => { syncedStateVersion = value; }, getLocalStateDirty: () => localStateDirty, setLocalStateDirty: (value) => { localStateDirty = value; } });
|
const syncStateToBackendOnce = () => syncStateToBackendHelper({ backend, t, getBackendUrl, buildPersistableState, getLocalStateVersion: () => localStateVersion, getSyncedStateVersion: () => syncedStateVersion, setSyncedStateVersion: (value) => { syncedStateVersion = value; }, getLocalStateDirty: () => localStateDirty, setLocalStateDirty: (value) => { localStateDirty = value; } });
|
||||||
|
// A save that fails (server restarting, network gone) is tried again every 5 s until it gets
|
||||||
|
// through, so "Changes waiting to save" never hangs when nothing else changes.
|
||||||
|
let syncRetryTimer = null;
|
||||||
|
const syncStateToBackend = async () => {
|
||||||
|
await syncStateToBackendOnce();
|
||||||
|
clearTimeout(syncRetryTimer);
|
||||||
|
syncRetryTimer = backend.writeError && localStateDirty ? setTimeout(() => { if (!backend.pendingWrites) void syncStateToBackend(); }, 5000) : null;
|
||||||
|
};
|
||||||
const pingBackend = () => pingBackendHelper({ backend, t, getBackendUrl });
|
const pingBackend = () => pingBackendHelper({ backend, t, getBackendUrl });
|
||||||
const checkAppVersion = () => checkAppVersionHelper({ onContact: (online) => {
|
const checkAppVersion = () => checkAppVersionHelper({ onContact: (online) => {
|
||||||
backend.available = online;
|
backend.available = online;
|
||||||
|
|||||||
@@ -37,10 +37,16 @@ export function mountDecoderSimSettings(root, { state, t, escapeHtml, getBackend
|
|||||||
if (running) {
|
if (running) {
|
||||||
await call("stop", {});
|
await call("stop", {});
|
||||||
// Back to the real decoder address.
|
// Back to the real decoder address.
|
||||||
state.settings.wsUrl = state.settings.simPreviousWsUrl || state.settings.wsUrl;
|
const fallback = state.settings.wsUrl === simUrl() ? "ws://127.0.0.1:9000" : state.settings.wsUrl;
|
||||||
|
state.settings.wsUrl = state.settings.simPreviousWsUrl || fallback;
|
||||||
delete state.settings.simPreviousWsUrl;
|
delete state.settings.simPreviousWsUrl;
|
||||||
} else {
|
} else {
|
||||||
await call("start", { lapSec: Number(root.querySelector("#simLapSec").value), spreadSec: Number(root.querySelector("#simSpreadSec").value) });
|
const lapSec = Number(root.querySelector("#simLapSec").value);
|
||||||
|
const spreadSec = Number(root.querySelector("#simSpreadSec").value);
|
||||||
|
await call("start", { lapSec, spreadSec });
|
||||||
|
// Kept with the settings so the server starts it again after a restart.
|
||||||
|
state.settings.simLapSec = lapSec;
|
||||||
|
state.settings.simSpreadSec = spreadSec;
|
||||||
if (state.settings.wsUrl !== simUrl()) state.settings.simPreviousWsUrl = state.settings.wsUrl;
|
if (state.settings.wsUrl !== simUrl()) state.settings.simPreviousWsUrl = state.settings.wsUrl;
|
||||||
state.settings.wsUrl = simUrl();
|
state.settings.wsUrl = simUrl();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ export function applyPersistedStateHelper(persisted, deps) {
|
|||||||
wsUrl: persisted.settings?.wsUrl || state.settings.wsUrl || "ws://127.0.0.1:9000",
|
wsUrl: persisted.settings?.wsUrl || state.settings.wsUrl || "ws://127.0.0.1:9000",
|
||||||
// The real decoder address while the decoder simulator is on (decoder_sim_view.js).
|
// The real decoder address while the decoder simulator is on (decoder_sim_view.js).
|
||||||
...(persisted.settings?.simPreviousWsUrl ? { simPreviousWsUrl: String(persisted.settings.simPreviousWsUrl) } : {}),
|
...(persisted.settings?.simPreviousWsUrl ? { simPreviousWsUrl: String(persisted.settings.simPreviousWsUrl) } : {}),
|
||||||
|
...(persisted.settings?.simLapSec ? { simLapSec: Number(persisted.settings.simLapSec), simSpreadSec: Number(persisted.settings.simSpreadSec ?? 1.5) } : {}),
|
||||||
splitDecoderEnabled: persisted.settings?.splitDecoderEnabled === true,
|
splitDecoderEnabled: persisted.settings?.splitDecoderEnabled === true,
|
||||||
splitWsUrl: String(persisted.settings?.splitWsUrl || state.settings.splitWsUrl || "ws://127.0.0.1:9001"),
|
splitWsUrl: String(persisted.settings?.splitWsUrl || state.settings.splitWsUrl || "ws://127.0.0.1:9001"),
|
||||||
pitDecoderEnabled: persisted.settings?.pitDecoderEnabled === true,
|
pitDecoderEnabled: persisted.settings?.pitDecoderEnabled === true,
|
||||||
|
|||||||
Reference in new issue
Block a user