Skip to content

Wait for local Supervisor startup during svc load - #10388

Open
officialasishkumar wants to merge 2 commits into
habitat-sh:mainfrom
officialasishkumar:retry-svc-load-during-startup
Open

Wait for local Supervisor startup during svc load#10388
officialasishkumar wants to merge 2 commits into
habitat-sh:mainfrom
officialasishkumar:retry-svc-load-during-startup

Conversation

@officialasishkumar

Copy link
Copy Markdown

Summary

  • Have hab svc load retry briefly when the local Supervisor control gateway refuses connections while a recent Supervisor LOCK file indicates startup is in progress.
  • Warn once that the local Supervisor is still starting, then wait and retry until the gateway accepts commands or the startup wait expires.
  • Leave remote Supervisor calls and normal not-running failures on the existing error path.

Testing

  • GIT_CONFIG_GLOBAL=/dev/null CARGO_NET_GIT_FETCH_WITH_CLI=true cargo test -p hab gateway_util

Fixes #6301.

Copilot AI review requested due to automatic review settings May 12, 2026 05:22
@officialasishkumar
officialasishkumar requested a review from a team as a code owner May 12, 2026 05:22
@chef-expeditor

Copy link
Copy Markdown
Contributor

Hello officialasishkumar! Thanks for the pull request!

Here is what will happen next:

  1. Your PR will be reviewed by the maintainers.
  2. If everything looks good, one of them will approve it, and your PR will be merged.

Thank you for contributing!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves hab svc load behavior when targeting a local Supervisor whose control gateway is temporarily unavailable during startup, by detecting a recent Supervisor LOCK file and retrying briefly instead of immediately failing with a generic connection-refused error.

Changes:

  • Add gateway_util::send_waiting_for_startup to retry on local ConnectionRefused when a recent Supervisor LOCK file suggests startup is in progress.
  • Emit a one-time warning while waiting, then retry until success or a startup-wait timeout.
  • Update hab svc load (CLI v4) to use the new startup-waiting send path and add unit tests for lock-file detection logic.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
components/hab/src/gateway_util.rs Adds local-startup wait/retry logic keyed off a recent Supervisor LOCK file, plus unit tests.
components/hab/src/cli_v4/svc/load.rs Routes hab svc load through the new startup-waiting gateway helper.

Comment on lines +58 to +70

loop {
match send(remote_sup_addr, msg.clone()).await {
Err(crate::error::Error::CtlClient(SrvClientError::ConnectionRefused))
if should_wait_for_local_supervisor_startup(remote_sup_addr, start.elapsed()) =>
{
if !warned {
let mut ui = UI::default_with_env();
let _ = ui.warn("The local Supervisor is not accepting commands yet; \
waiting for it to finish starting.");
warned = true;
}
tokio::time::sleep(SUPERVISOR_STARTUP_RETRY_INTERVAL).await;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in c4ef262: the lock-file freshness check is evaluated once, and retries are then gated by the startup wait window.

Comment thread components/hab/src/gateway_util.rs Outdated
Comment on lines +164 to +166
assert!(has_recent_supervisor_lock_file(&lock_file, Duration::from_secs(60)));
assert!(!has_recent_supervisor_lock_file(&lock_file, Duration::ZERO));
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in c4ef262: replaced the Duration::ZERO assertion with a small positive threshold after a short sleep.

Retry hab svc load while a local Supervisor lock file indicates startup is in progress. The command now warns once and waits briefly for the control gateway instead of immediately returning a connection-refused error.
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
@officialasishkumar
officialasishkumar force-pushed the retry-svc-load-during-startup branch from 46d1b68 to c4ef262 Compare May 13, 2026 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve error handling when Supervisor not started

2 participants