Reset Console session data and discard stale registration responses
This commit is contained in:
parent
54d5feaa91
commit
749d1a86f2
|
|
@ -0,0 +1,10 @@
|
|||
# Console 3.1.14
|
||||
|
||||
Release date: 2026-10-06.
|
||||
|
||||
- Clear It-Screen data, cached load timestamps and errors when the Console session changes. Previously, a 401 could leave Authorization required in the cloud-registration card after successful login alongside cached Registered/Logged in fields.
|
||||
- Bind asynchronous responses to the initiating session. Discard late responses from a previous session before processing their status; a stale 401 cannot invalidate the new session. Ignore cancelled/superseded It-Screen responses and prevent their cleanup from clearing newer requests.
|
||||
- Show Loading until the initial registration result arrives, instead of incorrectly displaying Not registered. Keep real current-session authorization and backend failures visible.
|
||||
- Preserve event-driven/manual It-Screen loading; no polling loops or retries added.
|
||||
|
||||
Validation: JavaScript regression checks for stale versus current-session 401 and app version; browser tests through the actual login form, two forced session-expiry/re-login cycles, and no extra registration requests while idle. Local Edge verification follows deployment.
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
"version": "1.0.0"
|
||||
},
|
||||
"stage_ui": {
|
||||
"version": "3.1.13"
|
||||
"version": "3.1.14"
|
||||
},
|
||||
"stage_avahi": {
|
||||
"version": "1.0.0"
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ APP_DIR = "/opt/iomatex-console"
|
|||
PUBLIC_DIR = os.path.join(APP_DIR, "public")
|
||||
PROVIDERS_DIR = os.path.join(APP_DIR, "providers.d")
|
||||
CONFIG_PATH = "/etc/iomatex/console.json"
|
||||
UI_VERSION = "V 3.1.13"
|
||||
UI_VERSION = "V 3.1.14"
|
||||
STORAGE_HEALTH_COMMAND = "/usr/local/sbin/iomatex-storage-health"
|
||||
ZONEINFO_ROOT = "/usr/share/zoneinfo"
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
const {chromium}=require('playwright');
|
||||
(async()=>{
|
||||
const b=await chromium.launch();const c=await b.newContext();const p=await c.newPage();const base='http://192.168.0.109';let fail=false, registrations=0;
|
||||
if(process.env.LOCAL_JS)await p.route('**/console.js*',r=>r.fulfill({path:'/repo/stage_ui/console_core/frontend/console.js'}));
|
||||
await p.route('**/api/itscreen/status',async r=>{if(fail){fail=false;return r.fulfill({status:401,json:{ok:false,error:'Authorization required'}})}return r.continue()});
|
||||
await p.route('**/api/itscreen/registration',async r=>{registrations++;return r.continue()});
|
||||
async function login(){await p.locator('#authPassword').fill(process.env.EDGE_PASSWORD);await p.locator('.authSubmitBtn').click();await p.locator('.authScreen').waitFor({state:'detached',timeout:60000});await p.locator('[data-tab="tscreen"]').waitFor({state:'visible'});await p.locator('[data-tab="tscreen"]').click();await p.waitForFunction(()=>document.querySelector('#itscreenRegistrationStatus')?.textContent.includes('4.410.142'),{},{timeout:30000});}
|
||||
await p.goto(base,{waitUntil:'domcontentloaded'});await login();
|
||||
for(let i=0;i<2;i++){
|
||||
fail=true;await p.evaluate(()=>window.__itscreenRefresh());await p.locator('#authPassword').waitFor();await login();
|
||||
const text=await p.locator('#itscreenRegistrationStatus').innerText();if(text.includes('Authorization required')||text.includes('\nError\n'))throw Error('Stale error after re-login: '+text);
|
||||
console.log('Re-login '+(i+1)+' has correct status and app version');
|
||||
}
|
||||
const before=registrations;await p.waitForTimeout(3000);if(registrations!==before)throw Error('Unexpected registration polling');
|
||||
await c.request.post(base+'/api/auth/logout',{data:{}});await b.close();
|
||||
})().catch(e=>{console.error(e);process.exit(1)});
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const vm = require('node:vm');
|
||||
const source = fs.readFileSync(path.join(__dirname, '../frontend/console.js'), 'utf8');
|
||||
(async()=>{
|
||||
for (const name of ['fetchJson','fetchJsonAllowLogicalFailure']) {
|
||||
let resolve;let expired=0;
|
||||
const ctx={state:{sessionGeneration:1},fetch:()=>new Promise(r=>resolve=r),setAuthRequired:()=>expired++,t:x=>x};
|
||||
vm.createContext(ctx);
|
||||
vm.runInContext(source.slice(source.indexOf(' async function fetchJson('),source.indexOf(' function replaceServiceCard(')),ctx);
|
||||
const old=ctx[name]('/api/itscreen/registration');
|
||||
ctx.state.sessionGeneration=2;
|
||||
resolve({status:401,ok:false,json:async()=>({error:'Authorization required'})});
|
||||
await assert.rejects(old,e=>e.name==='AbortError');assert.equal(expired,0,'Late 401 must not expire a new session');
|
||||
const current=ctx[name]('/api/itscreen/registration');
|
||||
resolve({status:401,ok:false,json:async()=>({error:'Authorization required'})});
|
||||
await assert.rejects(current,/Authorization required/);assert.equal(expired,1,'Current-session 401 must still require login');
|
||||
}
|
||||
console.log('Late-session responses discarded; real authentication failures preserved');
|
||||
})().catch(e=>{console.error(e);process.exitCode=1});
|
||||
|
|
@ -49,7 +49,7 @@
|
|||
{ mode: "test_by", label: "test.it-screen.by", host: "rest.test.it-screen.by" },
|
||||
{ mode: "custom", label: "Custom", host: "" }
|
||||
];
|
||||
const UI_VERSION = "V 3.1.13";
|
||||
const UI_VERSION = "V 3.1.14";
|
||||
const ITSCREEN_LOG_INITIAL_LINES = 50;
|
||||
const ITSCREEN_LOG_BUFFER_LIMIT = 300;
|
||||
const ITSCREEN_LOG_BATCH_MS = 250;
|
||||
|
|
@ -152,6 +152,7 @@
|
|||
|
||||
const state = {
|
||||
activeTab: "health",
|
||||
sessionGeneration: 0,
|
||||
identity: null,
|
||||
status: null,
|
||||
health: null,
|
||||
|
|
@ -1040,7 +1041,20 @@
|
|||
if (nodes.rebootBtn) nodes.rebootBtn.disabled = hide || state.rebootPending;
|
||||
}
|
||||
|
||||
function resetSessionRequests() {
|
||||
state.sessionGeneration += 1;
|
||||
state.healthRequest = null;
|
||||
cancelItscreenRequest();
|
||||
cancelItscreenRegistrationRequest();
|
||||
Object.assign(state.itscreen, {
|
||||
data: null, runtime: null, error: "", details: "", message: "",
|
||||
loadedAt: 0, registrationLoadedAt: 0, loading: false,
|
||||
request: null, registrationRequest: null
|
||||
});
|
||||
}
|
||||
|
||||
function setAuthRequired(message) {
|
||||
resetSessionRequests();
|
||||
state.auth.loading = false;
|
||||
state.auth.authenticated = false;
|
||||
state.auth.busy = false;
|
||||
|
|
@ -1060,6 +1074,7 @@
|
|||
}
|
||||
|
||||
function applyAuthSession(payload, message) {
|
||||
if (!state.auth.authenticated && payload && payload.authenticated) resetSessionRequests();
|
||||
state.auth.loading = false;
|
||||
state.auth.authenticated = !!(payload && payload.authenticated);
|
||||
state.auth.busy = false;
|
||||
|
|
@ -1636,7 +1651,7 @@
|
|||
}
|
||||
|
||||
function itscreenStatusMeta(payload) {
|
||||
if (!payload) return { label: t("Loading"), tone: "warn" };
|
||||
if (!payload || (!state.itscreen.registrationLoadedAt && !state.itscreen.error)) return { label: t("Loading"), tone: "warn" };
|
||||
if (state.itscreen.busyAction === "register") return { label: t("Registering..."), tone: "warn" };
|
||||
if (payload.status === "error" || state.itscreen.error) return { label: t("Error"), tone: "error" };
|
||||
if (payload.status === "incomplete" || (payload.local_registered && !payload.logged)) return { label: t("Registration incomplete"), tone: "warn" };
|
||||
|
|
@ -1803,7 +1818,7 @@
|
|||
const warnings = Array.isArray(card.warnings) ? card.warnings : [];
|
||||
const errors = Array.isArray(card.errors) ? card.errors : [];
|
||||
const registrationIncomplete = !!(payload && payload.local_registered && !payload.logged);
|
||||
const registrationRequired = !!(payload && !payload.registered && !state.itscreen.error);
|
||||
const registrationRequired = !!(state.itscreen.registrationLoadedAt && payload && !payload.registered && !state.itscreen.error);
|
||||
|
||||
return `
|
||||
<article class="panel card serviceCard">
|
||||
|
|
@ -3016,7 +3031,7 @@
|
|||
: (hostError || (selectedServerDiffers ? t("Register the device on the newly selected server.") : t("Select the target cloud server and start registration.")));
|
||||
const serviceWarnings = Array.isArray(service && service.warnings) ? service.warnings : [];
|
||||
const serviceErrors = Array.isArray(service && service.errors) ? service.errors : [];
|
||||
const registrationRequired = !!(payload && !payload.registered && !state.itscreen.error);
|
||||
const registrationRequired = !!(state.itscreen.registrationLoadedAt && payload && !payload.registered && !state.itscreen.error);
|
||||
const registrationWarnClass = registrationRequired ? "registrationWarn" : "";
|
||||
const registrationWarnKeyClass = registrationRequired ? "key registrationWarn" : "key";
|
||||
|
||||
|
|
@ -4840,8 +4855,14 @@
|
|||
}
|
||||
|
||||
async function fetchJson(url, options) {
|
||||
const generation = state.sessionGeneration;
|
||||
const response = await fetch(url, options || { cache: "no-store" });
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
if (generation !== state.sessionGeneration) {
|
||||
const error = new Error("Discarded response from a previous session");
|
||||
error.name = "AbortError";
|
||||
throw error;
|
||||
}
|
||||
if (response.status === 401) {
|
||||
if (String(url || "").indexOf("/api/auth/login") !== 0) {
|
||||
setAuthRequired(t("Session expired, please sign in again"));
|
||||
|
|
@ -4860,8 +4881,14 @@
|
|||
}
|
||||
|
||||
async function fetchJsonAllowLogicalFailure(url, options) {
|
||||
const generation = state.sessionGeneration;
|
||||
const response = await fetch(url, options || { cache: "no-store" });
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
if (generation !== state.sessionGeneration) {
|
||||
const error = new Error("Discarded response from a previous session");
|
||||
error.name = "AbortError";
|
||||
throw error;
|
||||
}
|
||||
if (response.status === 401) {
|
||||
if (String(url || "").indexOf("/api/auth/login") !== 0) {
|
||||
setAuthRequired(t("Session expired, please sign in again"));
|
||||
|
|
@ -4900,6 +4927,7 @@
|
|||
}
|
||||
|
||||
async function loadHealth() {
|
||||
const generation = state.sessionGeneration;
|
||||
if (state.healthRequest) return state.healthRequest;
|
||||
state.healthRequest = (async () => {
|
||||
const [summary, services] = await Promise.all([
|
||||
|
|
@ -4916,7 +4944,7 @@
|
|||
try {
|
||||
return await state.healthRequest;
|
||||
} finally {
|
||||
state.healthRequest = null;
|
||||
if (generation === state.sessionGeneration) state.healthRequest = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -5072,9 +5100,13 @@
|
|||
}
|
||||
cancelItscreenRegistrationRequest();
|
||||
state.itscreen.registrationRequestController = typeof AbortController === "function" ? new AbortController() : null;
|
||||
const controller = state.itscreen.registrationRequestController;
|
||||
const generation = state.sessionGeneration;
|
||||
const isCurrent = () => generation === state.sessionGeneration && state.itscreen.registrationRequestController === controller;
|
||||
state.itscreen.registrationRequest = (async () => {
|
||||
try {
|
||||
const payload = await requestItscreenRegistration();
|
||||
if (!isCurrent()) return itscreenRegistration();
|
||||
const nextData = state.itscreen.data || {};
|
||||
const registrationPayload = (payload && payload.data && typeof payload.data === "object")
|
||||
? payload.data
|
||||
|
|
@ -5093,14 +5125,17 @@
|
|||
if (state.activeTab === "tscreen" || state.activeTab === "health") renderActiveTab();
|
||||
return state.itscreen.data.registration;
|
||||
} catch (error) {
|
||||
if (!isCurrent()) return itscreenRegistration();
|
||||
if (error && error.name === "AbortError") return itscreenRegistration();
|
||||
state.itscreen.error = error.message || t("Cloud registration status is unavailable");
|
||||
state.itscreen.details = "";
|
||||
if (state.activeTab === "tscreen" || state.activeTab === "health") renderActiveTab();
|
||||
return itscreenRegistration();
|
||||
} finally {
|
||||
state.itscreen.registrationRequestController = null;
|
||||
state.itscreen.registrationRequest = null;
|
||||
if (isCurrent()) {
|
||||
state.itscreen.registrationRequestController = null;
|
||||
state.itscreen.registrationRequest = null;
|
||||
}
|
||||
}
|
||||
})();
|
||||
return state.itscreen.registrationRequest;
|
||||
|
|
@ -5113,6 +5148,9 @@
|
|||
if (!force && state.itscreen.loadedAt && Date.now() - state.itscreen.loadedAt < maxAgeMs) return state.itscreen.data;
|
||||
cancelItscreenRequest();
|
||||
state.itscreen.requestController = typeof AbortController === "function" ? new AbortController() : null;
|
||||
const controller = state.itscreen.requestController;
|
||||
const generation = state.sessionGeneration;
|
||||
const isCurrent = () => generation === state.sessionGeneration && state.itscreen.requestController === controller;
|
||||
state.itscreen.loading = true;
|
||||
if (force) {
|
||||
state.itscreen.error = "";
|
||||
|
|
@ -5122,6 +5160,7 @@
|
|||
try {
|
||||
// Initial IT-Screen render must not wait on MQTT-backed registration.
|
||||
const [payload, runtime] = await Promise.all([requestItscreenStatus(), requestItscreenRuntime()]);
|
||||
if (!isCurrent()) return state.itscreen.data;
|
||||
const currentData = state.itscreen.data || {};
|
||||
state.itscreen.data = { ...currentData, ...(payload.ok === false ? (payload.data || {}) : payload) };
|
||||
state.itscreen.runtime = runtime;
|
||||
|
|
@ -5129,13 +5168,14 @@
|
|||
state.itscreen.loadedAt = Date.now();
|
||||
if (!state.itscreen.registrationLoadedAt || force) {
|
||||
window.setTimeout(() => {
|
||||
if ((state.activeTab === "tscreen" || state.activeTab === "health") && state.auth.authenticated) {
|
||||
if (generation === state.sessionGeneration && (state.activeTab === "tscreen" || state.activeTab === "health") && state.auth.authenticated) {
|
||||
loadItscreenRegistration({ force, maxAgeMs: 30000 }).catch(() => {});
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
return state.itscreen.data;
|
||||
} catch (error) {
|
||||
if (!isCurrent()) return state.itscreen.data;
|
||||
if (error && error.name === "AbortError") {
|
||||
return state.itscreen.data;
|
||||
}
|
||||
|
|
@ -5160,9 +5200,11 @@
|
|||
};
|
||||
return state.itscreen.data;
|
||||
} finally {
|
||||
state.itscreen.loading = false;
|
||||
state.itscreen.requestController = null;
|
||||
state.itscreen.request = null;
|
||||
if (isCurrent()) {
|
||||
state.itscreen.loading = false;
|
||||
state.itscreen.requestController = null;
|
||||
state.itscreen.request = null;
|
||||
}
|
||||
}
|
||||
})();
|
||||
return state.itscreen.request;
|
||||
|
|
@ -5204,6 +5246,7 @@
|
|||
renderActiveTab();
|
||||
return;
|
||||
}
|
||||
const generation = state.sessionGeneration;
|
||||
const preserveEditing = !!options.preserveEditing;
|
||||
nodes.refreshBtn.disabled = true;
|
||||
if (nodes.rebootBtn) nodes.rebootBtn.disabled = state.rebootPending;
|
||||
|
|
@ -5221,6 +5264,7 @@
|
|||
} else {
|
||||
await loadStatus();
|
||||
}
|
||||
if (generation !== state.sessionGeneration) return;
|
||||
if (!(preserveEditing && state.activeTab === "network" && networkFormIsInteractive()) && !(preserveEditing && state.activeTab === "tscreen" && itscreenFormIsInteractive()) && !(preserveEditing && state.activeTab === "security" && timezoneFormIsInteractive())) {
|
||||
renderActiveTab();
|
||||
} else if (state.activeTab === "network") {
|
||||
|
|
@ -5229,9 +5273,10 @@
|
|||
updateTimezoneFormUi();
|
||||
}
|
||||
} catch (error) {
|
||||
if (generation !== state.sessionGeneration || error.name === "AbortError") return;
|
||||
nodes.content.innerHTML = `<div class="empty">${esc(t("Failed to load {tab}: {message}", { tab: state.activeTab, message: error.message || String(error) }))}</div>`;
|
||||
} finally {
|
||||
nodes.refreshBtn.disabled = state.rebootPending;
|
||||
nodes.refreshBtn.disabled = !state.auth.authenticated || state.rebootPending;
|
||||
if (nodes.rebootBtn) nodes.rebootBtn.disabled = state.rebootPending;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
} catch (error) {}
|
||||
})();
|
||||
</script>
|
||||
<link rel="stylesheet" href="/console.css?v=3.1.13&rev=camera-snapshot-1">
|
||||
<link rel="stylesheet" href="/console.css?v=3.1.14&rev=camera-snapshot-1">
|
||||
</head>
|
||||
<body>
|
||||
<main class="shell">
|
||||
|
|
@ -109,7 +109,7 @@
|
|||
</main>
|
||||
<div id="menuBackdrop" class="menuBackdrop" hidden></div>
|
||||
<div id="toastStack" class="toastStack" aria-live="polite" aria-atomic="true"></div>
|
||||
<script src="/console.i18n.js?v=3.1.13&rev=camera-snapshot-1"></script>
|
||||
<script src="/console.js?v=3.1.13&rev=camera-snapshot-1"></script>
|
||||
<script src="/console.i18n.js?v=3.1.14&rev=camera-snapshot-1"></script>
|
||||
<script src="/console.js?v=3.1.14&rev=camera-snapshot-1"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
{
|
||||
"version": "3.1.13"
|
||||
"version": "3.1.14"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue