test(sync): audit browser recovery paths
This commit is contained in:
@@ -443,6 +443,21 @@ async function continuePendingWork() {
|
||||
setTimeout(() => synchronize(validatePending(commands[0])).catch(failPermanently), 0);
|
||||
}
|
||||
|
||||
async function renewOfflineLease(command) {
|
||||
if (stopped || root.getAttribute("data-sync-phase") !== "offline") return;
|
||||
const lease = await claimUploaderLease(database);
|
||||
publishLease(lease);
|
||||
if (!lease.leader) {
|
||||
setPhase("standby", "Another tab owns sync; waiting for lease takeover.");
|
||||
leaseTimer = setTimeout(() => runLeaseLoop(command).catch(failPermanently), LEASE_POLL_MS);
|
||||
return;
|
||||
}
|
||||
leaseTimer = setTimeout(
|
||||
() => renewOfflineLease(command).catch(failPermanently),
|
||||
LEASE_MS / 2,
|
||||
);
|
||||
}
|
||||
|
||||
async function synchronize(command) {
|
||||
if (synchronizing) return;
|
||||
synchronizing = true;
|
||||
@@ -455,7 +470,10 @@ async function synchronize(command) {
|
||||
}
|
||||
clearTimeout(leaseTimer);
|
||||
leaseTimer = setTimeout(() => {
|
||||
if (!stopped && root.getAttribute("data-sync-phase") !== "acknowledged") {
|
||||
if (stopped || root.getAttribute("data-sync-phase") === "acknowledged") return;
|
||||
if (root.getAttribute("data-sync-phase") === "offline") {
|
||||
renewOfflineLease(command).catch(failPermanently);
|
||||
} else {
|
||||
synchronize(command).catch(failPermanently);
|
||||
}
|
||||
}, LEASE_MS / 2);
|
||||
|
||||
Reference in New Issue
Block a user