Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): report a refused or partial infrastructure restart

Yudhi Armyndharis5878363bc1e5
diff --git a/dashboard/src/hooks/useRestartFlow.ts b/dashboard/src/hooks/useRestartFlow.ts
index 437dec14a..b5cc41793 100644
--- a/dashboard/src/hooks/useRestartFlow.ts
+++ b/dashboard/src/hooks/useRestartFlow.ts
@@ -16,6 +16,10 @@ export interface RestartFlow {
showRestartModal: boolean;
restartCountdown: number;
restartStatus: RestartStatus;
+ /** The server's reason when it refused the restart; shown in place of the generic error text. */
+ restartError: string | null;
+ /** Services the server reported it could not start or stop; the page does not reload over them. */
+ restartWarnings: string[];
pendingProfiles: string[];
runningProfiles: string[];
dbSwitch: boolean;
@@ -39,6 +43,8 @@ export function useRestartFlow(): RestartFlow {
const [showRestartModal, setShowRestartModal] = useState(false);
const [restartCountdown, setRestartCountdown] = useState(0);
const [restartStatus, setRestartStatus] = useState<RestartStatus>('idle');
+ const [restartError, setRestartError] = useState<string | null>(null);
+ const [restartWarnings, setRestartWarnings] = useState<string[]>([]);
const [profiles, setProfiles] = useState<{ pending: string[]; running: string[] }>({
pending: [],
running: [],
@@ -101,7 +107,7 @@ export function useRestartFlow(): RestartFlow {
if (restartStatus === 'idle') setShowRestartModal(false);
};
- const checkServerHealth = (estimatedTime?: number) => {
+ const checkServerHealth = (estimatedTime: number | undefined, hasWarnings: boolean) => {
let attempts = 0;
const maxAttempts = restartPollAttempts(estimatedTime);
@@ -111,7 +117,8 @@ export function useRestartFlow(): RestartFlow {
stopCountdown();
setRestartCountdown(0);
setRestartStatus('success');
- schedulePollTimeout(() => window.location.reload(), 2000);
+ // With warnings on screen the operator reloads by hand, after reading them.
+ if (!hasWarnings) schedulePollTimeout(() => window.location.reload(), 2000);
} catch {
attempts++;
if (attempts < maxAttempts) schedulePollTimeout(check, 1000);
@@ -131,12 +138,24 @@ export function useRestartFlow(): RestartFlow {
// Kept outside the try: the poll deadline is derived from it, and the restart call is expected to
// fail sometimes (the server may go down before it answers).
let estimatedTime: number | undefined;
+ let warnings: string[] = [];
try {
const response = await infraApi.restart(profiles.pending, profilesToRemove);
estimatedTime = response.estimatedTime;
if (response.estimatedTime) setRestartCountdown(response.estimatedTime);
- } catch {
- // Expected — server shutting down
+ warnings = [...(response.orchestration?.errors ?? []), ...(response.removal?.errors ?? [])];
+ setRestartWarnings(warnings);
+ } catch (err) {
+ // An HTTP status (a proxy 502/503/504 included) means no shutdown was confirmed and the old
+ // process may still be serving, so a readiness poll would report a restart that never happened.
+ // Only a status-less network failure is the expected sign of the server going down mid-answer.
+ if (typeof (err as { status?: unknown } | null)?.status === 'number') {
+ stopCountdown();
+ setRestartCountdown(0);
+ setRestartError(err instanceof Error ? err.message : String(err));
+ setRestartStatus('error');
+ return;
+ }
}
setRestartStatus('waiting');
@@ -151,13 +170,15 @@ export function useRestartFlow(): RestartFlow {
});
}, 1000);
- checkServerHealth(estimatedTime);
+ checkServerHealth(estimatedTime, warnings.length > 0);
};
return {
showRestartModal,
restartCountdown,
restartStatus,
+ restartError,
+ restartWarnings,
pendingProfiles: profiles.pending,
runningProfiles: profiles.running,
dbSwitch,
diff --git a/dashboard/src/pages/Infrastructure.test.ts b/dashboard/src/pages/Infrastructure.test.ts
index fedc26b8a..f41acb12a 100644
--- a/dashboard/src/pages/Infrastructure.test.ts
+++ b/dashboard/src/pages/Infrastructure.test.ts
@@ -87,6 +87,7 @@ let overrides: {
savedFails?: boolean;
statusFails?: boolean;
currentEngine?: { engineType: string };
+ restart?: () => Response;
} = {};
// ENGINE_TYPE supplied by the container environment, so the dashboard cannot change it.
@@ -165,6 +166,7 @@ function installFetchStub(): void {
);
}
if (method === 'POST' && path === '/api/infra/restart') {
+ if (overrides.restart) return Promise.resolve(overrides.restart());
return Promise.resolve(
jsonResponse({ message: 'restarting', restarting: true, profiles: [], profilesToRemove: [], estimatedTime: 5 }),
);
@@ -679,3 +681,72 @@ test('unmounting mid-restart cancels the health poll and countdown timers', { ti
assert.equal(findFetchCall('GET', '/api/health/ready'), undefined);
});
+
+// ── Restart outcomes the server reports ──────────────────────────────────────
+
+test('a refused restart shows the server reason and never polls readiness', { timeout: 10_000 }, async () => {
+ const { screen, fireEvent, within } = rtl;
+ resetFetchCalls();
+ // The old process refused before scheduling a shutdown, so it is still up: a readiness poll would
+ // answer 200 and report a restart that never happened.
+ overrides = { restart: () => jsonResponse({ message: 'Too many restart requests' }, 429) };
+ renderInfrastructure();
+
+ await screen.findByText('Database Configuration');
+ fireEvent.click(screen.getByRole('button', { name: 'Save Configuration' }));
+ const dialog = await screen.findByRole('dialog');
+ fireEvent.click(within(dialog).getByRole('button', { name: 'Restart Now' }));
+
+ await within(dialog).findByText('Restart failed');
+ assert.ok(within(dialog).getByText('Too many restart requests'), 'the server reason is not shown');
+ // Past the first readiness poll (3s), which a restart assumed to be under way would have sent.
+ await new Promise(resolve => setTimeout(resolve, 3500));
+ assert.equal(findFetchCall('GET', '/api/health/ready'), undefined);
+ assert.equal(within(dialog).queryByText('Server ready'), null);
+});
+
+test(
+ 'services that failed to start are shown after the restart instead of reloading over them',
+ { timeout: 15_000 },
+ async () => {
+ const { screen, fireEvent, within } = rtl;
+ resetFetchCalls();
+ const failure = 'Failed to start minio: image pull failed';
+ overrides = {
+ restart: () =>
+ jsonResponse({
+ message: 'restarting',
+ restarting: true,
+ profiles: ['minio'],
+ profilesToRemove: [],
+ estimatedTime: 5,
+ orchestration: { success: false, message: 'Some services failed', errors: [failure] },
+ }),
+ };
+ // jsdom cannot navigate, so a reload reports itself through console.error; count those.
+ const navigations: string[] = [];
+ const consoleError = console.error;
+ console.error = (...args: unknown[]) => {
+ const text = args.map(a => (a instanceof Error ? a.message : String(a))).join(' ');
+ if (text.includes('navigation')) navigations.push(text);
+ else consoleError(...args);
+ };
+ try {
+ renderInfrastructure();
+ await screen.findByText('Database Configuration');
+ fireEvent.click(screen.getByRole('button', { name: 'Save Configuration' }));
+ const dialog = await screen.findByRole('dialog');
+ fireEvent.click(within(dialog).getByRole('button', { name: 'Restart Now' }));
+
+ await within(dialog).findByText('Server ready', {}, { timeout: 5_000 });
+ assert.ok(within(dialog).getByText(failure), 'the orchestration error is not shown');
+ assert.ok(within(dialog).getByRole('button', { name: 'Reload Page' }), 'no way to reload after reading');
+ assert.equal(within(dialog).queryByText('Server is back online! The page will reload automatically.'), null);
+ // Past the 2s after which a clean restart reloads the page.
+ await new Promise(resolve => setTimeout(resolve, 2500));
+ assert.deepEqual(navigations, [], 'the page reloaded over the warning');
+ } finally {
+ console.error = consoleError;
+ }
+ },
+);
diff --git a/dashboard/src/pages/Infrastructure.tsx b/dashboard/src/pages/Infrastructure.tsx
index 4a2c9f0ee..916338f6c 100644
--- a/dashboard/src/pages/Infrastructure.tsx
+++ b/dashboard/src/pages/Infrastructure.tsx
@@ -876,13 +876,29 @@ export function Infrastructure() {
{restartFlow.restartStatus === 'success' && (
<>
<CheckCircle size={48} className="restart-status-icon" />
- <p className="restart-success-msg">{t('infrastructure.restart.successMsg')}</p>
+ {restartFlow.restartWarnings.length === 0 ? (
+ <p className="restart-success-msg">{t('infrastructure.restart.successMsg')}</p>
+ ) : (
+ <>
+ <div className="migration-warning" role="alert">
+ <AlertTriangle size={18} />
+ <div>
+ {restartFlow.restartWarnings.map((warning, index) => (
+ <p key={index}>{warning}</p>
+ ))}
+ </div>
+ </div>
+ <button className="btn-primary" onClick={() => window.location.reload()}>
+ {t('infrastructure.restart.reload')}
+ </button>
+ </>
+ )}
</>
)}
{restartFlow.restartStatus === 'error' && (
<>
- <p className="restart-error-msg">{t('infrastructure.restart.errorMsg')}</p>
+ <p className="restart-error-msg">{restartFlow.restartError ?? t('infrastructure.restart.errorMsg')}</p>
<button className="btn-primary" onClick={() => window.location.reload()}>
{t('infrastructure.restart.reload')}
</button>
diff --git a/dashboard/src/services/api.ts b/dashboard/src/services/api.ts
index 8fbb76485..ae3d101dd 100644
--- a/dashboard/src/services/api.ts
+++ b/dashboard/src/services/api.ts
@@ -1148,6 +1148,9 @@ export const infraApi = {
profiles: string[];
profilesToRemove: string[];
estimatedTime: number;
+ // Present only when Docker started or stopped built-in services; `errors` lists what failed.
+ orchestration?: { errors?: string[] };
+ removal?: { errors?: string[] };
}>('/infra/restart', {
method: 'POST',
body: JSON.stringify({ profiles: profiles || [], profilesToRemove: profilesToRemove || [] }),