Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
77b5698
fix(api): /flux/info refuses before FluxOS has connected to its database
MorningLightMountain713 Nov 16, 2026
dfda51f
fix(apps): backup and restore hold an app through the reconciler, and…
MorningLightMountain713 Nov 16, 2026
845d486
fix(election): read an app's run state once FDM has answered, and cou…
MorningLightMountain713 Nov 16, 2026
cc770a8
test(harness): 2209's failed restore leaves the folder half-replaced,…
MorningLightMountain713 Nov 16, 2026
a038424
test(harness): a backup and a failed restore hold their app through t…
MorningLightMountain713 Nov 16, 2026
ee18cd7
test(harness): 2209's unsafe-volume case takes the volume once the pr…
MorningLightMountain713 Nov 16, 2026
7cea618
test(harness): the fixture's same-block nodes sort into the ring in i…
MorningLightMountain713 Nov 16, 2026
0fa6c89
test(harness): 2276 reads its patched folder back while a pass waits …
MorningLightMountain713 Nov 16, 2026
eafcbaf
fix(apps): a failed restore holds what it broke, in every sync mode, …
MorningLightMountain713 Nov 16, 2026
4560302
test(harness): a restore's record and its clear are observable
MorningLightMountain713 Nov 17, 2026
60630a1
test(harness): a lone g: component a restore left part replaced stays…
MorningLightMountain713 Nov 17, 2026
02cbee7
test(harness): a g: component a restore left part replaced heals only…
MorningLightMountain713 Nov 17, 2026
986e9a7
test(harness): a restore left part replaced is released only by new d…
MorningLightMountain713 Nov 17, 2026
9ecf8c4
fix(syncthing): a receive-only folder whose only local changes are de…
MorningLightMountain713 Nov 17, 2026
ba45b41
fixup! test(harness): a restore left part replaced is released only b…
MorningLightMountain713 Nov 17, 2026
0b9f5a0
fixup! test(harness): a restore left part replaced is released only b…
MorningLightMountain713 Nov 17, 2026
5c9eb38
fixup! test(harness): a restore left part replaced is released only b…
MorningLightMountain713 Nov 17, 2026
03180cf
fixup! test(harness): a restore left part replaced is released only b…
MorningLightMountain713 Nov 17, 2026
2ff0757
fixup! test(harness): a lone g: component a restore left part replace…
MorningLightMountain713 Nov 17, 2026
afea8d5
fix(apps): a restore's restart of the other instances leaves their ow…
MorningLightMountain713 Nov 17, 2026
69fd3ee
fixup! test(harness): a restore left part replaced is released only b…
MorningLightMountain713 Nov 17, 2026
60b8c81
fixup! test(harness): a restore left part replaced is released only b…
MorningLightMountain713 Nov 17, 2026
98fc185
fixup! test(harness): a g: component a restore left part replaced hea…
MorningLightMountain713 Nov 17, 2026
e1f7110
test(harness): the election does not resume a held copy left paused a…
MorningLightMountain713 Nov 17, 2026
d0e888a
fix(syncthing): a held folder heals only from a connected peer that h…
MorningLightMountain713 Nov 17, 2026
1bbe589
test(harness): a copy whose restore deleted nothing stays held while …
MorningLightMountain713 Nov 17, 2026
2a85ccc
test(harness): the paused-and-sending case takes an app of its own
MorningLightMountain713 Nov 17, 2026
6b6c2b1
test(harness): a crash case releases FluxOS before it asserts what th…
MorningLightMountain713 Nov 17, 2026
667934b
refactor(apps): containerCrashRecovery is containerEventsConsumer
MorningLightMountain713 Nov 17, 2026
fd10b4f
fix(apps): a run something asked Docker to stop did not die, and its …
MorningLightMountain713 Nov 17, 2026
ad16368
test(harness): the paused-and-sending case shares the suite's app
MorningLightMountain713 Nov 17, 2026
177250c
test(harness): a node's syncthing links to its peers are dropped at o…
MorningLightMountain713 Nov 18, 2026
4ddfa3a
test(harness): H9b releases the standbys' elections one at a time
MorningLightMountain713 Nov 18, 2026
298be39
fix(syncthing): a restore record that cannot be read decides nothing,…
MorningLightMountain713 Nov 18, 2026
5de7ee9
feat(syncthing): a holder that stops being ready says so
MorningLightMountain713 Nov 18, 2026
994ff18
test(harness): 4406, a restore record that cannot be read changes no …
MorningLightMountain713 Nov 18, 2026
c45bbb2
fix(restore): a component whose record cannot be cleared is a failed …
MorningLightMountain713 Nov 18, 2026
340f024
fix(routes): the component-states route sits above the app-control ro…
MorningLightMountain713 Nov 18, 2026
78415e7
docs(routes): the app-control routes' middleware order states its rule
MorningLightMountain713 Nov 18, 2026
a909386
fix(reconciler): a backup or restore takes the answer of the pass its…
MorningLightMountain713 Nov 18, 2026
23f0ccf
test(harness): 44 restarts docker once the backup's hold has stopped …
MorningLightMountain713 Nov 18, 2026
ebda429
fix(sync): a node taking an app's folder on deletes none of its data
MorningLightMountain713 Nov 20, 2026
cf0c80c
test(harness): suites wait for the sync layer to take a folder on
MorningLightMountain713 Nov 20, 2026
fb36a80
fix(sync): a held folder heals only on counts scanned since the restore
MorningLightMountain713 Nov 20, 2026
11b6c3a
test(harness): 4404 heals a copy whose demotion was refused only once…
MorningLightMountain713 Nov 20, 2026
387c957
fix(sync): a folder pass reads the restore record once
MorningLightMountain713 Nov 20, 2026
af8e1b1
fix(backup): an operation releases the components its stop held
MorningLightMountain713 Nov 20, 2026
09742c1
fix(sync): a held folder heals on counts from a scan it asked for
MorningLightMountain713 Nov 20, 2026
577ab69
test(harness): 4404's refused demotion is cleared only after the scan…
MorningLightMountain713 Nov 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions ZelBack/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const {
rejectQueryParameters,
requireAppStateReady,
requireBootSettled,
requireDatabase,
requirePolicyReady,
requireRegistryReady,
} = require('./services/utils/routeGuards');
Expand Down Expand Up @@ -282,7 +283,7 @@ module.exports = (app) => {
app.get('/flux/nodetier', cache('30 seconds'), asyncRoute((req, res) => {
return fluxService.getNodeTier(req, res);
}));
app.get('/flux/info', cache('60 seconds'), asyncRoute((req, res) => {
app.get('/flux/info', requireDatabase, cache('60 seconds'), asyncRoute((req, res) => {
return fluxService.getFluxInfo(req, res);
}));
app.get('/flux/timezone', asyncRoute((req, res) => {
Expand Down Expand Up @@ -1007,18 +1008,12 @@ module.exports = (app) => {
app.get('/apps/requestmessage/:hash', asyncRoute((req, res) => {
return messageVerifier.requestAppMessageAPI(req, res);
}));
// alwaysRespond BEFORE requireBootSettled, on all eight app-control routes.
//
// Not for the reason it looks like. A 503 from the boot gate cannot collapse
// into a bodiless 304 whichever way round these go: express's req.fresh
// returns false unless the status is 2xx or 304, so a conditional request can
// never turn a 503 into one, whatever ETag it carries. Verified across
// bootSettled x order x six request shapes.
//
// The real reason is smaller: reversed, the 503 goes out with no Cache-Control
// header at all instead of no-store, because alwaysRespond never runs. Worth
// keeping, and worth writing down - two middlewares in an order with no stated
// reason is an invitation to swap them.
// Whether each component of an app runs here, and why one does not.
app.get('/apps/componentstates/:appname?', asyncRoute((req, res) => {
return appController.componentStates(req, res);
}));
// App-control routes run alwaysRespond before requireBootSettled, so the boot
// gate's 503 also carries Cache-Control: no-store.
app.get('/apps/appstart/:appname?/:global?', alwaysRespond, requireBootSettled, asyncRoute((req, res) => {
return appController.appStart(req, res);
}));
Expand Down
456 changes: 221 additions & 235 deletions ZelBack/src/services/appLifecycle/advancedWorkflows.js

Large diffs are not rendered by default.

20 changes: 18 additions & 2 deletions ZelBack/src/services/appLifecycle/appInstaller.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const portClaims = require('../appNetwork/portClaims');
const globalState = require('../utils/globalState');
const fluxosTrial = require('../utils/fluxosTrial');
const folderStates = require('../appMonitoring/folderStates');
const appsRuntimeState = require('../appManagement/appsRuntimeState');
const { checkAndDecryptAppSpecs } = require('../utils/enterpriseHelper');
const { verifyEncryptedSpec } = require('../utils/enterpriseSpec');
const { specificationFormatter } = require('../utils/appSpecHelpers');
Expand Down Expand Up @@ -1033,8 +1034,23 @@ async function installApplicationSoft(appSpecifications, appName, isComponent, r
res.write(serviceHelper.ensureString(startStatus));
if (res.flush) res.flush();
}
if (start && !appSpecifications.containerData.includes('g:')) {
const identifier = isComponent ? `${appSpecifications.name}_${appName}` : appName;
const startedHere = start && !appSpecifications.containerData.includes('g:');
const componentId = isComponent ? `${appSpecifications.name}_${appName}` : appName;
// A soft install keeps the volume, and with it a restore that did not finish
// on it: such a component is not started here, and the reconciler keeps it
// stopped until the record is cleared. An unread record holds it too.
const restoreHolds = startedHere
&& await appsRuntimeState.isRestoreUnfinished(componentId).catch(() => true);
if (restoreHolds) {
const held = { status: `${componentId} is not started: a restore of its data did not finish` };
log.warn(held);
if (res) {
res.write(serviceHelper.ensureString(held));
if (res.flush) res.flush();
}
}
if (startedHere && !restoreHolds) {
const identifier = componentId;
const app = await dockerService.appDockerStart(identifier);
if (!app) {
throw new Error(`Failed to start ${identifier} container`);
Expand Down
21 changes: 19 additions & 2 deletions ZelBack/src/services/appLifecycle/primaryRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ async function sendThenRun(identifier, appId, change) {
// folder stops sending
log.error(`primaryRole - not starting ${identifier}: ${error.message}`);
await syncthingFolderWrites.changeSyncthingFolderType(appId, 'receiveonly');
return { to: Role.STANDBY, reason: 'its operator lock could not be read' };
return { to: Role.STANDBY, reason: 'its operator lock or restore record could not be read' };
}
const { RunRequest } = appReconciler;
if (outcome === RunRequest.WRITTEN) return Role.PRIMARY;
Expand All @@ -116,6 +116,10 @@ async function sendThenRun(identifier, appId, change) {
// decides an operator start.
return { to: Role.STANDBY, reason: 'its operator stopped it' };
}
if (outcome === RunRequest.RESTORE_UNFINISHED) {
await syncthingFolderWrites.changeSyncthingFolderType(appId, 'receiveonly');
return { to: Role.STANDBY, reason: 'a restore of its data did not finish' };
}
// Stood down, or another decision was made while it waited: nothing runs it
// here, so its folder stops sending, and the next election pass decides again.
await syncthingFolderWrites.changeSyncthingFolderType(appId, 'receiveonly');
Expand Down Expand Up @@ -229,14 +233,21 @@ async function adopt(identifier, state, reason) {
* restart the container runs with no opinion recorded, and the reconciler acts on
* the component, a pending restart included, only once one is
* (appReconciler.adoptControllerDesired). Writes nothing while a change of role
* is in progress. The folder write may be refused - a volume not mounted - and
* is in progress, while an intent other than running is recorded, or while a
* backup or restore holds the app. The folder write may be refused - a volume not mounted - and
* the adoption is asked for all the same: it records what the container shows.
* @param {string} identifier `<component>_<app>`
* @param {string} appId Syncthing folder id
* @returns {Promise<void>}
*/
async function holdAsPrimary(identifier, appId) {
if (changes.get(identifier)) return;
// This node is the primary only while its recorded intent is running; with
// another recorded (a failed restore's, an unsafe mount's), it is not, and its
// folder must not send. A backup or restore holds the folder, which alone may
// resume it.
if (appReconciler.hasControllerOpinion(identifier) && !isPrimary(identifier)) return;
if (heldByOperation(identifier)) return;
await syncthingFolderWrites.changeSyncthingFolderType(appId, 'sendreceive');
await adopt(identifier, 'running', 'masterSlave primary');
}
Expand Down Expand Up @@ -306,6 +317,12 @@ async function holdAsStandby(identifier, appId, { othersHold } = {}) {
if (discarded) fluxEventBus.publish('primaryRole:returned', { identifier, outcome: 'discarded' });
return;
}
// A restore left its data part replaced: it stays paused, sending nothing, until
// the record is cleared.
if (await syncthingFolderWrites.restoreHolds(appId)) {
fluxEventBus.count('primaryRole:returned', identifier, 'restoreUnfinished');
return;
}
// It is the component's writer, and no other holder has taken over: it goes
// on as the primary. Its folder never stops sending, so a peer asking meanwhile
// reads it holding the component.
Expand Down
92 changes: 91 additions & 1 deletion ZelBack/src/services/appManagement/appController.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ async function runGlobalCommandHere(runHere, appname, paramA) {
* @param {Function} [runHere] - This node's share, called as runHere(appname, paramA)
* @returns {Promise<void>}
*/
async function executeAppGlobalCommand(appname, command, zelidauth, paramA, runHere) {
async function executeAppGlobalCommand(appname, command, zelidauth, paramA, runHere, { query } = {}) {
try {
// get a list of the specific app locations
const locations = await appLocation(appname);
Expand All @@ -163,6 +163,7 @@ async function executeAppGlobalCommand(appname, command, zelidauth, paramA, runH
if (paramA) {
url += `/${paramA}`;
}
if (query) url += `?${query}`;
// Fire-and-forget: each node's delivery, with its own bounded retry of a
// boot-gate 503, runs on its own while the loop paces the sends.
deliverGlobalCommand(url, axiosConfig);
Expand Down Expand Up @@ -311,6 +312,12 @@ async function setAppOperatorStopped(appname, stopped, { awaitPass = false, forc
? { force, asPrimary: await holdsElectedApp(electedIds) }
: { force };
if (!awaitsElection) await appsRuntimeState.setOperatorStopped(id, stopped, lockOptions);
// A start is the owner accepting the component's data as it is, including
// a folder a restore left half-replaced. A restart is not: it is what a
// restore sends every other instance, and it accepts nothing.
if (!stopped && !alsoRestart && await appsRuntimeState.isRestoreUnfinished(id)) {
await appsRuntimeState.setRestoreUnfinished(id, false);
}
// Raised inside the same slot as the lock, so a pass cannot read one
// without the other and bounce a container the operator meant to keep down.
if (alsoRestart) await appsRuntimeState.requestRestart(id);
Expand Down Expand Up @@ -383,6 +390,8 @@ const PENDING_REASONS = {
policy: 'its restart policy does not allow it to run',
invalidSpec: 'its specification cannot be actuated',
notInstalled: 'it is not installed on this node',
restoreUnfinished: 'a restore of its data did not finish: restore it again, or start it to keep its data as it is',
operationHold: 'a backup or restore holds it',
};

/**
Expand Down Expand Up @@ -656,6 +665,15 @@ async function appRestart(req, res) {
return res.json(errMessage);
}

// Another instance's restore asks this one to read the data it replaced: what
// runs is restarted, and what its owner stopped stays stopped.
if (serviceHelper.ensureBoolean(req.query?.unlessstopped || false)) {
const { restarted, appName: restartedName } = await restartUnlessStopped(appname);
return res.json(messageHelper.createDataMessage(restarted.length
? `Application ${restartedName} will be restarted: ${restarted.join(', ')}`
: `Application ${restartedName} was not restarted: its owner stopped it`));
}

if (global) {
executeAppGlobalCommand(appname, 'apprestart', authOf(req), undefined, restartHere); // do not wait
const appResponse = messageHelper.createSuccessMessage(`${appname} queried for global restart`);
Expand Down Expand Up @@ -878,7 +896,79 @@ async function stopAllNonFluxRunningApps() {
}
}

/**
* Restarts the components of an app here that their owner has not stopped, and
* changes no stop lock and no restore record. A component whose lock cannot be
* read is not restarted: an unread lock is not an absent one.
* @param {string} appname Application or component name.
* @returns {Promise<{ids: string[], restarted: string[], appName: string}>}
*/
async function restartUnlessStopped(appname) {
const { ids, appName } = await operatorTargetIds(appname);
const restarted = [];
// eslint-disable-next-line no-restricted-syntax
for (const id of ids) {
// eslint-disable-next-line no-await-in-loop
await appReconciler.applyIntent(id, async () => {
const stopped = await appsRuntimeState.operatorStoppedOrThrow(id).catch((error) => {
log.warn(`restartUnlessStopped - ${id}: not restarted, its stop lock could not be read: ${error.message}`);
return true;
});
if (!stopped) {
await appsRuntimeState.requestRestart(id);
restarted.push(id);
}
fluxEventBus.publish('app:restartRequested', { identifier: dockerService.getBaseAppName(id), restarted: !stopped });
});
}
return { ids, restarted, appName };
}

/**
* Each component of an app on this node: whether its container runs, whether
* the reconciler means it to, and its reason when it does not - an operator stop,
* an unfinished restore, a backup or restore holding it, the election, its
* restart policy. The app's owner and the Flux team, who start and stop it.
* @param {object} req Request with `appname` in params or query.
* @param {object} res Response.
* @returns {Promise<object>}
*/
async function componentStates(req, res) {
try {
let { appname } = req.params;
appname = appname || req.query.appname;
if (!appname) {
throw new Error('No Flux App specified');
}
const mainAppName = appname.split('_')[1] || appname;
// eslint-disable-next-line global-require
const verificationHelper = require('../verificationHelper');
const authorized = await verificationHelper.verifyPrivilege(Privilege.APP_OWNER_OR_FLUX_TEAM, authOf(req), { appName: mainAppName });
if (!authorized) {
return res.json(messageHelper.errUnauthorizedMessage());
}
const { ids } = await operatorTargetIds(appname);
const states = await Promise.all(ids.map(async (id) => {
const [actual, verdict] = await Promise.all([appReconciler.dockerActual(id), appReconciler.desiredRunState(id)]);
return {
component: id,
// null when docker could not tell
running: actual.reachable === false || actual.indeterminate ? null : actual.running === true,
// null while a component the election decides has no decision yet
desired: verdict.desired,
reason: verdict.reason ?? null,
};
}));
return res.json(messageHelper.createDataMessage(states));
} catch (error) {
log.error(error);
return res.json(messageHelper.createErrorMessage(error.message, error.name, error.code));
}
}

module.exports = {
componentStates,
restartUnlessStopped,
executeAppGlobalCommand,
deliverGlobalCommand,
appStart,
Expand Down
Loading
Loading