Skip to content

Commit

Permalink
feat(up): ✨ timeout and offer to kill running up if hanging (#879)
Browse files Browse the repository at this point in the history
The `omni up` (and respectively `omni down`) command will try to attach
to any running `omni up` or `omni down` command that is already running
for the current work directory. However, in cases where there is a
connectivity issue (e.g. computer going to sleep), it is possible for
the `omni up` command to hang indefinitely (e.g. waiting for a network
response).

When attaching to a running process, this will trigger a timeout after a
few minutes if the process seems to be hanging, offering the user to
kill the running process.

Closes #877
  • Loading branch information
xaf authored Jan 9, 2025
1 parent 9bbb0f5 commit 1a2b219
Show file tree
Hide file tree
Showing 6 changed files with 274 additions and 59 deletions.
16 changes: 10 additions & 6 deletions src/internal/commands/builtin/up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1515,13 +1515,17 @@ impl BuiltinCommand for UpCommand {
if suggest_clone {
init_options.insert(SyncUpdateInitOption::SuggestClone);
}
SyncUpdateInit::Up(
head_commit.clone(),
init_options,
self.cli_args().cache_enabled,
)
SyncUpdateInit::Up {
commit: head_commit.clone(),
options: init_options,
cache: self.cli_args().cache_enabled,
pid: Some(std::process::id()),
}
} else {
SyncUpdateInit::Down(self.cli_args().cache_enabled)
SyncUpdateInit::Down {
cache: self.cli_args().cache_enabled,
pid: Some(std::process::id()),
}
};

// Prepare a listener in case the operation is already running
Expand Down
31 changes: 26 additions & 5 deletions src/internal/config/parser/up_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use serde::Serialize;
use crate::internal::config::parser::errors::ConfigErrorHandler;
use crate::internal::config::parser::errors::ConfigErrorKind;
use crate::internal::config::utils::check_allowed;
use crate::internal::config::utils::parse_duration_or_default;
use crate::internal::config::ConfigScope;
use crate::internal::config::ConfigValue;

Expand All @@ -14,6 +15,8 @@ pub struct UpCommandConfig {
pub auto_bootstrap: bool,
pub notify_workdir_config_updated: bool,
pub notify_workdir_config_available: bool,
pub attach_kill_timeout: u64,
pub attach_lock_timeout: u64,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub preferred_tools: Vec<String>,
pub mise_version: String,
Expand All @@ -25,18 +28,22 @@ pub struct UpCommandConfig {
impl Default for UpCommandConfig {
fn default() -> Self {
Self {
attach_kill_timeout: Self::DEFAULT_ATTACH_KILL_TIMEOUT,
attach_lock_timeout: Self::DEFAULT_ATTACH_LOCK_TIMEOUT,
auto_bootstrap: Self::DEFAULT_AUTO_BOOTSTRAP,
mise_version: Self::DEFAULT_MISE_VERSION.to_string(),
notify_workdir_config_updated: Self::DEFAULT_NOTIFY_WORKDIR_CONFIG_UPDATED,
notify_workdir_config_available: Self::DEFAULT_NOTIFY_WORKDIR_CONFIG_AVAILABLE,
operations: UpCommandOperationConfig::default(),
preferred_tools: Vec::new(),
mise_version: Self::DEFAULT_MISE_VERSION.to_string(),
upgrade: Self::DEFAULT_UPGRADE,
operations: UpCommandOperationConfig::default(),
}
}
}

impl UpCommandConfig {
const DEFAULT_ATTACH_KILL_TIMEOUT: u64 = 300; // 5 minutes
const DEFAULT_ATTACH_LOCK_TIMEOUT: u64 = 5; // 5 seconds
const DEFAULT_AUTO_BOOTSTRAP: bool = true;
const DEFAULT_NOTIFY_WORKDIR_CONFIG_UPDATED: bool = true;
const DEFAULT_NOTIFY_WORKDIR_CONFIG_AVAILABLE: bool = true;
Expand All @@ -57,6 +64,18 @@ impl UpCommandConfig {
.reject_scope(&ConfigScope::Workdir)
.unwrap_or_default();

let attach_kill_timeout = parse_duration_or_default(
config_value.get("attach_kill_timeout").as_ref(),
Self::DEFAULT_ATTACH_KILL_TIMEOUT,
&error_handler.with_key("attach_kill_timeout"),
);

let attach_lock_timeout = parse_duration_or_default(
config_value.get("attach_lock_timeout").as_ref(),
Self::DEFAULT_ATTACH_LOCK_TIMEOUT,
&error_handler.with_key("attach_lock_timeout"),
);

let auto_bootstrap = config_value_global.get_as_bool_or_default(
"auto_bootstrap",
Self::DEFAULT_AUTO_BOOTSTRAP,
Expand Down Expand Up @@ -99,13 +118,15 @@ impl UpCommandConfig {
);

Self {
attach_kill_timeout,
attach_lock_timeout,
auto_bootstrap,
notify_workdir_config_updated,
mise_version,
notify_workdir_config_available,
notify_workdir_config_updated,
operations,
preferred_tools,
mise_version,
upgrade,
operations,
}
}
}
Expand Down
Loading

0 comments on commit 1a2b219

Please sign in to comment.