From c2d77db080ebb248ff5e9dc8b3c6d0144443f6c7 Mon Sep 17 00:00:00 2001 From: Luc Bocahut Date: Mon, 23 Nov 2026 09:56:51 +0100 Subject: [PATCH] Retry readiness probes that outlast a short timeout on a large store Each probe opens and integrity-checks the store. At 1.1 GB that takes over five seconds, so the fixed per-probe timeout aborted updates. Closes #344 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01GvCDky7pWJx1VVhmNxftM4 --- forge/host_setup.py | 2 +- forge/host_update.py | 40 +++++++++++++++++++-------------------- tests/test_host_update.py | 11 +++++++++++ 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/forge/host_setup.py b/forge/host_setup.py index 6e2eb56d..94b492a7 100644 --- a/forge/host_setup.py +++ b/forge/host_setup.py @@ -432,7 +432,7 @@ def main(): print('For a remote VM, forward port 8787 over SSH to reach the loopback dashboard.') return 0 except (OSError, ValueError, StateError, StoreError, subprocess.SubprocessError) as error: - print('Setup did not finish: ' + (str(error) if isinstance(error, (ValueError, StateError, StoreError)) else 'Host command failed; correct it and rerun setup.'), file=sys.stderr) + print('Setup did not finish: ' + (str(error) if isinstance(error, (ValueError, StateError, StoreError)) else 'Host command failed (' + str(error) + '); correct it and rerun setup.'), file=sys.stderr) return 1 except KeyboardInterrupt: print('\nSetup interrupted. Saved connections are retained; rerun setup to continue.', file=sys.stderr) diff --git a/forge/host_update.py b/forge/host_update.py index 135ec0ae..8b2cad3b 100644 --- a/forge/host_update.py +++ b/forge/host_update.py @@ -511,32 +511,32 @@ def qualify_boundary_engine(): image='sha256:' + '0' * 64).qualify() -def wait_mirror(root, *, timeout=20): +def wait_service(root, module, failure, *, timeout=90): + # Each probe opens and integrity-checks the store, which takes seconds once + # the database is large; give every probe the remaining time, not a fixed slice. deadline = time.monotonic() + timeout while True: - result = subprocess.run(['/usr/bin/python3', '-m', 'forge.launch', 'forge.mirror_daemon', - '--root', str(root), '--check'], - env={**os.environ, 'PYTHONPATH': str(SOURCE)}, - capture_output=True, text=True, timeout=5) - if result.returncode == 0: - return + try: + result = subprocess.run(['/usr/bin/python3', '-m', 'forge.launch', module, '--root', str(root), '--check'], + env={**os.environ, 'PYTHONPATH': str(SOURCE)}, capture_output=True, text=True, + timeout=max(1, deadline - time.monotonic())) + if result.returncode == 0: + return + except subprocess.TimeoutExpired: + pass if time.monotonic() >= deadline: - raise ValueError('The job mirror service is unhealthy. Inspect forge-mirror.service and rerun the supported update.') + raise ValueError(failure) time.sleep(.25) -def wait_registry(root, *, timeout=20): - deadline = time.monotonic() + timeout - while True: - result = subprocess.run(['/usr/bin/python3', '-m', 'forge.launch', 'forge.registry_cache', - '--root', str(root), '--check'], - env={**os.environ, 'PYTHONPATH': str(SOURCE)}, - capture_output=True, text=True, timeout=5) - if result.returncode == 0: - return - if time.monotonic() >= deadline: - raise ValueError('The package cache service is unhealthy. Inspect forge-registry.service and rerun the supported update.') - time.sleep(.25) +def wait_mirror(root): + wait_service(root, 'forge.mirror_daemon', + 'The job mirror service is unhealthy. Inspect forge-mirror.service and rerun the supported update.') + + +def wait_registry(root): + wait_service(root, 'forge.registry_cache', + 'The package cache service is unhealthy. Inspect forge-registry.service and rerun the supported update.') def qualify_runner(image, seccomp, profile, *, full=False): diff --git a/tests/test_host_update.py b/tests/test_host_update.py index c1f48884..d30c97e0 100644 --- a/tests/test_host_update.py +++ b/tests/test_host_update.py @@ -614,5 +614,16 @@ def test_update_verifies_connected_accounts_when_the_runner_changed(self): check.assert_not_called() +class ServiceReadinessTests(unittest.TestCase): + def test_slow_probe_is_retried_within_the_overall_deadline(self): + # A large store makes one probe outlast a short per-call timeout. + calls = [subprocess.TimeoutExpired('probe', 5), subprocess.CompletedProcess('probe', 0)] + with patch.object(host_update.subprocess, 'run', side_effect=calls) as run, \ + patch.object(host_update.time, 'sleep'): + host_update.wait_mirror('/root') + self.assertEqual(run.call_count, 2) + self.assertGreater(run.call_args.kwargs['timeout'], 5) + + if __name__ == '__main__': unittest.main()