mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
#6520: the Problems "Status" page showed "Board data-repair — 146/146 boards" running forever (plus a matching "Migration or repair" login warning), and the CPU area showed dozens of "new problems" on an idle server. Board repair stuck at "running": getInProgress() trusted the raw `running` flag. The startup repair DOES write running:false on completion, but its progress callback also fired a NON-awaited running:true write when boardsDone === boardsTotal; being fire-and-forget, that write could land AFTER the awaited completion write and pin the doc at "running, 146/146". A process killed mid-repair leaves running:true too. Both now clear: * the startup progress callback no longer writes the terminal boardsDone === boardsTotal update (the completion write owns the final state), closing the race at the source; * getInProgress() now asks the new pure isStatusActive() instead of reading `running` directly - a doc is "in progress" only while running AND not in a terminal phase (completed/error/done) AND not already finished by count (done >= total) AND updated recently (a running flag with no recent progress write is a crashed run). This also heals docs already stuck on an instance, and fixes the same class of stale flag for the text migration. Because the login "Migration or repair" warning keys off getInProgress(), it clears too. CPU "57 new problems" on an idle server: the count in eventLogProblemAreas counted every unacknowledged row in a stream. The CPU monitor writes one 'detected' row when a high-CPU period starts and several severity:'info' rows ('remediated' when it ends, 'rate-limited' for mitigation, FerretDB governor chatter), so each brief, already-over spike looked like several "new problems". The count now excludes severity:'info' rows (via the new newProblemsSelector) - notices that a problem was handled or cleared are not problems. Rows with no severity are still counted, so nothing unclassified is silently dropped. Both decisions are pure, unit- and negative-tested (statusActive.test.cjs, eventLogProblems.test.cjs), and registered in test:unit:node. Thanks to Alishara and xet7 ! Fixes #6520,
107 lines
4.4 KiB
JavaScript
107 lines
4.4 KiB
JavaScript
'use strict';
|
|
|
|
// Unit + negative tests for isStatusActive (#6520): deciding whether a persisted
|
|
// migration / board-repair status doc is STILL running or has a stale
|
|
// `running:true`. The bug was the Admin Panel → Problems "Status" page showing
|
|
// "Board data-repair — 146/146 boards" (and a matching "Migration or repair"
|
|
// warning) forever, because it trusted the raw `running` flag.
|
|
//
|
|
// Run: node tests/statusActive.test.cjs
|
|
|
|
const assert = require('assert');
|
|
const { isStatusActive, DEFAULT_STALE_MS } = require('../models/lib/statusActive.js');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
|
|
|
|
const NOW = 1_700_000_000_000;
|
|
const recent = () => new Date(NOW - 1000).toISOString();
|
|
function active(doc) { return isStatusActive(doc, { now: NOW }); }
|
|
|
|
console.log('statusActive:');
|
|
|
|
test('a live repair mid-way, updated recently, IS active', () => {
|
|
assert.strictEqual(active({
|
|
running: true, phase: 'repairing', boardsDone: 40, boardsTotal: 146, updatedAt: recent(),
|
|
}), true);
|
|
});
|
|
|
|
// The exact reported bug: a completion write raced with a late progress write and
|
|
// lost, leaving running:true at 146/146.
|
|
test('running:true but done === total is FINISHED, not active (146/146)', () => {
|
|
assert.strictEqual(active({
|
|
running: true, phase: 'repairing', boardsDone: 146, boardsTotal: 146, updatedAt: recent(),
|
|
}), false);
|
|
});
|
|
|
|
test('done > total (overshoot) is also finished', () => {
|
|
assert.strictEqual(active({
|
|
running: true, phase: 'repairing', boardsDone: 150, boardsTotal: 146, updatedAt: recent(),
|
|
}), false);
|
|
});
|
|
|
|
test('a terminal phase is never active, whatever the flag says', () => {
|
|
for (const phase of ['completed', 'error', 'done']) {
|
|
assert.strictEqual(active({
|
|
running: true, phase, boardsDone: 10, boardsTotal: 146, updatedAt: recent(),
|
|
}), false, `phase ${phase} must not be active`);
|
|
}
|
|
});
|
|
|
|
test('running:false is never active', () => {
|
|
assert.strictEqual(active({
|
|
running: false, phase: 'repairing', boardsDone: 40, boardsTotal: 146, updatedAt: recent(),
|
|
}), false);
|
|
});
|
|
|
|
// A process killed mid-repair leaves running:true with no completion write.
|
|
test('a stale running flag (no recent update) is not active — crashed run', () => {
|
|
assert.strictEqual(active({
|
|
running: true, phase: 'repairing', boardsDone: 40, boardsTotal: 146,
|
|
updatedAt: new Date(NOW - DEFAULT_STALE_MS - 1000).toISOString(),
|
|
}), false);
|
|
});
|
|
|
|
test('just inside the stale window is still active; just outside is not', () => {
|
|
const base = { running: true, phase: 'repairing', boardsDone: 5, boardsTotal: 146 };
|
|
assert.strictEqual(active({ ...base, updatedAt: new Date(NOW - DEFAULT_STALE_MS + 1000).toISOString() }), true);
|
|
assert.strictEqual(active({ ...base, updatedAt: new Date(NOW - DEFAULT_STALE_MS - 1000).toISOString() }), false);
|
|
});
|
|
|
|
test('a running doc with no total yet (boardsTotal 0) is active if recent', () => {
|
|
// The initial startup write sets boardsTotal:0 before the count is known - it
|
|
// must still count as in progress (the done>=total guard only fires when a real
|
|
// total is known).
|
|
assert.strictEqual(active({
|
|
running: true, phase: 'repairing', boardsDone: 0, boardsTotal: 0, updatedAt: recent(),
|
|
}), true);
|
|
});
|
|
|
|
test('the text migration uses the collections pair while migrating', () => {
|
|
assert.strictEqual(active({
|
|
running: true, phase: 'migrating', collectionsDone: 3, collectionsTotal: 8, updatedAt: recent(),
|
|
}), true);
|
|
assert.strictEqual(active({
|
|
running: true, phase: 'migrating', collectionsDone: 8, collectionsTotal: 8, updatedAt: recent(),
|
|
}), false);
|
|
});
|
|
|
|
test('null / undefined / empty docs are not active (negative)', () => {
|
|
for (const d of [null, undefined, {}, { running: true }]) {
|
|
// { running:true } with no updatedAt and no total: recent-enough (updated 0 is
|
|
// treated as "no timestamp", not stale) and no total to have reached, so it is
|
|
// active - a freshly-flagged run. Only the first three must be false.
|
|
if (d && d.running) continue;
|
|
assert.strictEqual(active(d), false);
|
|
}
|
|
// A bare running flag with nothing else is treated as active (freshly started).
|
|
assert.strictEqual(active({ running: true }), true);
|
|
});
|
|
|
|
test('a doc with no updatedAt is not treated as stale', () => {
|
|
// updated === 0 means "no timestamp recorded", which must not read as ancient.
|
|
assert.strictEqual(active({ running: true, phase: 'repairing', boardsDone: 1, boardsTotal: 5 }), true);
|
|
});
|
|
|
|
console.log(`\n${passed} tests passed`);
|