Skip to content

Commit b22d792

Browse files
committed
fix: Handle --timeout 0 correctly as unlimited instead of ignoring it
1 parent 0a2ce8a commit b22d792

5 files changed

Lines changed: 15 additions & 14 deletions

File tree

src/app/dispatcher.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub async fn dispatch_command(cli: &Cli, ctx: &AppContext) -> Result<()> {
8888
cli.password,
8989
#[cfg(target_os = "macos")]
9090
use_keychain,
91-
Some(cli.timeout),
91+
cli.timeout,
9292
Some(cli.connect_timeout),
9393
)
9494
.await
@@ -347,9 +347,11 @@ async fn handle_exec_command(cli: &Cli, ctx: &AppContext, command: &str) -> Resu
347347
std::process::exit(0);
348348
} else {
349349
// Regular command execution
350-
let timeout = if cli.timeout > 0 {
351-
Some(cli.timeout)
350+
let timeout = if let Some(t) = cli.timeout {
351+
// User explicitly specified --timeout, use it directly (including 0 for unlimited)
352+
Some(t)
352353
} else {
354+
// User did not specify --timeout, fall back to config
353355
ctx.config
354356
.get_timeout(ctx.cluster_name.as_deref().or(cli.cluster.as_deref()))
355357
};

src/cli/bssh.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,9 @@ pub struct Cli {
169169

170170
#[arg(
171171
long,
172-
default_value = "300",
173-
help = "Command timeout in seconds (0 for unlimited)"
172+
help = "Command timeout in seconds (0 for unlimited, default: 300 if not specified)"
174173
)]
175-
pub timeout: u64,
174+
pub timeout: Option<u64>,
176175

177176
#[arg(
178177
long = "connect-timeout",

src/cli/pdsh.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ impl PdshCli {
282282
// Map -t to --connect-timeout
283283
connect_timeout: self.connect_timeout.unwrap_or(30),
284284
// Map -u to --timeout
285-
timeout: self.command_timeout.unwrap_or(300),
285+
timeout: self.command_timeout,
286286
// Map -N to --no-prefix
287287
no_prefix: self.no_prefix,
288288
// Map -b to --batch
@@ -526,7 +526,7 @@ mod tests {
526526
// Connect timeout
527527
assert_eq!(bssh_cli.connect_timeout, 60);
528528
// Command timeout
529-
assert_eq!(bssh_cli.timeout, 600);
529+
assert_eq!(bssh_cli.timeout, Some(600));
530530
// No prefix flag
531531
assert!(bssh_cli.no_prefix);
532532
// Batch flag
@@ -547,8 +547,8 @@ mod tests {
547547

548548
// Default connect timeout (30s)
549549
assert_eq!(bssh_cli.connect_timeout, 30);
550-
// Default command timeout (300s)
551-
assert_eq!(bssh_cli.timeout, 300);
550+
// Default command timeout (None - will use config or 300s default)
551+
assert_eq!(bssh_cli.timeout, None);
552552
// Default parallel (32 from pdsh fanout)
553553
assert_eq!(bssh_cli.parallel, 32);
554554
// Default strict host key checking

tests/fail_fast_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ fn test_fail_fast_flag_combinations() {
314314
];
315315
let cli = Cli::try_parse_from(args).expect("Should parse with fail-fast and timeout");
316316
assert!(cli.fail_fast);
317-
assert_eq!(cli.timeout, 60);
317+
assert_eq!(cli.timeout, Some(60));
318318
}
319319

320320
/// Test that -k doesn't conflict with existing short options

tests/pdsh_compat_test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ fn test_pdsh_to_bssh_default_timeouts() {
280280

281281
// Default connect timeout is 30s
282282
assert_eq!(bssh_cli.connect_timeout, 30);
283-
// Default command timeout is 300s
284-
assert_eq!(bssh_cli.timeout, 300);
283+
// Default command timeout (None - will use config or 300s default)
284+
assert_eq!(bssh_cli.timeout, None);
285285
}
286286

287287
#[test]
@@ -291,7 +291,7 @@ fn test_pdsh_to_bssh_custom_timeouts() {
291291
let bssh_cli = pdsh_cli.to_bssh_cli();
292292

293293
assert_eq!(bssh_cli.connect_timeout, 10);
294-
assert_eq!(bssh_cli.timeout, 600);
294+
assert_eq!(bssh_cli.timeout, Some(600));
295295
}
296296

297297
#[test]

0 commit comments

Comments
 (0)