Skip to content

feat: Add --fail-fast option to stop on first failure (pdsh -k compatibility) #94

Closed

Description

@inureyes

Summary

Add a new --fail-fast option to bssh that stops execution immediately when any node fails (connection error or non-zero exit code). This is a prerequisite for pdsh compatibility mode (meta-issue #91).

Parent Issue

Part of #91 (pdsh compatibility mode) - Phase 1: New Options for Feature Parity

Background

pdsh provides -k option that causes the tool to fail fast on any error:

  • Connection failure to any host
  • Non-zero return code from any command

This is useful for:

  • Critical operations where partial execution is unacceptable
  • Deployment scripts where all nodes must succeed
  • Validation checks across clusters

Proposed Implementation

CLI Interface

# Default behavior (continue on failure)
bssh -H "node1,node2,node3" "risky-command"
# Continues even if node1 fails, reports all results at end

# Fail-fast mode
bssh -H "node1,node2,node3" --fail-fast "risky-command"
# Stops immediately if any node fails, cancels pending operations

Option Definition

#[arg(
    short = 'k',
    long = "fail-fast",
    help = "Stop execution immediately on first failure\nCancels pending commands when any node fails or returns non-zero"
)]
pub fail_fast: bool,

Implementation Tasks

  • Add --fail-fast / -k option to Cli struct in src/cli.rs
  • Implement failure detection in executor
  • Add cancellation mechanism for pending/running tasks
  • Implement proper cleanup of cancelled SSH sessions
  • Report which node caused the failure
  • Add unit and integration tests
  • Update help text and examples

Acceptance Criteria

  • Connection failure to any host triggers immediate stop
  • Non-zero exit code from any command triggers immediate stop
  • Pending (not yet started) commands are cancelled
  • Running commands are terminated gracefully
  • Error message clearly indicates which node failed and why
  • Exit code reflects the failure appropriately
  • Works with all execution modes (TUI, stream, normal)

Technical Considerations

  • Need to implement cancellation tokens or similar mechanism
  • Should integrate with tokio's task cancellation
  • Consider using tokio::select! for early termination
  • May need to track which tasks have started vs pending

Interaction with Other Options

  • --fail-fast + --require-all-success: Both require all nodes to succeed, but fail-fast stops early
  • --fail-fast + --parallel N: Should cancel pending tasks in the semaphore queue

Notes

  • Short option -k does not conflict with existing bssh options
  • This complements the existing --require-all-success and --check-all-nodes options

Activity

  1. added
    pdsh-compatpdsh compatibility mode features
    and removed on Dec 16, 2025
  2. added a commit that references this issue on Dec 16, 2025
    fc3abbc
  3. added 2 commits that reference this issue on Dec 16, 2025
    9ff851e
    c30f91d
  4. self-assigned this
    on Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions