From a943ed62e2a45e9fde51e9a0b855b5b38fed7e63 Mon Sep 17 00:00:00 2001 From: Nicolas Cantu Date: Tue, 6 Jan 2026 14:32:17 +0100 Subject: [PATCH] Remove retry mechanism from SSH connections MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Motivations:** - Retries are useless, connection must work on first attempt or fail - Simplifying code by removing unnecessary retry logic - Reducing complexity and potential for multiple connection attempts **Root causes:** - Retry mechanism was adding complexity without real benefit - If SSH connection fails, retrying won't help, it should fail immediately **Correctifs:** - Removed all retry logic from ssh_exec() function - Simplified to single attempt execution - Kept socket validation and cleanup before execution - Removed retry loop and counter variables **Evolutions:** - Simpler and more straightforward SSH connection handling - Faster failure detection when connection issues occur **Pages affectées:** - deploy.sh: Simplified ssh_exec() function, removed retry mechanism --- deploy.sh | 50 +++++++++++++++----------------------------------- 1 file changed, 15 insertions(+), 35 deletions(-) diff --git a/deploy.sh b/deploy.sh index ff5d152..44eff2a 100644 --- a/deploy.sh +++ b/deploy.sh @@ -33,44 +33,24 @@ check_ssh_connection() { ssh -O check -o ControlPath="${SSH_CONTROL_PATH}" ${SERVER} 2>/dev/null || return 1 } -# Fonction pour exécuter une commande SSH avec connexion persistante et gestion d'erreurs robuste +# Fonction pour exécuter une commande SSH avec connexion persistante ssh_exec() { - local max_retries=2 - local retry_count=0 - - while [ $retry_count -lt $max_retries ]; do - # Nettoyer le socket s'il existe mais est invalide - if [ -S "${SSH_CONTROL_PATH}" ]; then - if ! check_ssh_connection; then - # Connexion morte, nettoyer avant de réessayer - cleanup_dead_ssh - fi + # Nettoyer le socket s'il existe mais est invalide + if [ -S "${SSH_CONTROL_PATH}" ]; then + if ! check_ssh_connection; then + # Connexion morte, nettoyer avant d'exécuter + cleanup_dead_ssh fi + fi - # Exécuter la commande SSH - # Si le socket existe mais est invalide, SSH avec ControlMaster=auto le détectera et créera une nouvelle connexion - if ssh -o ControlMaster=auto \ - -o ControlPath="${SSH_CONTROL_PATH}" \ - -o ControlPersist=300 \ - -o ConnectTimeout=10 \ - -o ServerAliveInterval=60 \ - -o ServerAliveCountMax=3 \ - ${SERVER} "$@" 2>&1; then - return 0 - else - local exit_code=$? - retry_count=$((retry_count + 1)) - - if [ $retry_count -lt $max_retries ]; then - # Nettoyer la connexion morte avant de réessayer - cleanup_dead_ssh - sleep 1 - else - # Dernière tentative échouée, retourner le code d'erreur - return $exit_code - fi - fi - done + # Exécuter la commande SSH (une seule tentative, pas de retry) + ssh -o ControlMaster=auto \ + -o ControlPath="${SSH_CONTROL_PATH}" \ + -o ControlPersist=300 \ + -o ConnectTimeout=10 \ + -o ServerAliveInterval=60 \ + -o ServerAliveCountMax=3 \ + ${SERVER} "$@" 2>&1 } # Nettoyer les connexions SSH persistantes et le répertoire temporaire à la fin