**Motivations:**
- Too many SSH connection attempts were being made during deployment
- ControlMaster socket cleanup was not aggressive enough
- Multiple SSH calls at step 5 created excessive connection attempts
**Root causes:**
- ControlMaster socket could remain but be invalid, causing SSH to disable multiplexing
- Each ssh_exec had up to 3 retries, and step 5 made 4-5 ssh_exec calls
- Socket cleanup was not forceful enough to remove invalid sockets
- Complex retry logic at step 5 created unnecessary SSH calls
**Correctifs:**
- Improved cleanup_dead_ssh() to forcefully remove socket and wait for proper closure
- Reduced max retries in ssh_exec from 3 to 2
- Simplified step 5 logic to reduce SSH calls from 4-5 to 2 (one check, one init if needed)
- Combined Git initialization commands into single SSH call to reduce connections
- Added sleep after socket cleanup to ensure proper closure
**Evolutions:**
- More efficient SSH connection management
- Reduced deployment time by minimizing connection attempts
**Pages affectées:**
- deploy.sh: Improved cleanup_dead_ssh(), reduced retries, simplified step 5 logic
**Motivations:**
- Deployment script was blocking at step 5 (Git repository verification)
- Command substitution with SSH could hang indefinitely
- Need to avoid blocking on SSH connection failures
**Root causes:**
- Command substitution \ with ssh_exec could block if SSH connection hangs
- Complex logic with grep on command output was fragile
- No proper timeout handling in the verification step
**Correctifs:**
- Simplified Git repository verification logic
- Removed command substitution that could block
- Use direct exit code checking instead of parsing output
- Improved error handling with explicit SSH exit code checking
- Added cleanup and retry mechanism for connection failures
**Evolutions:**
- More robust Git repository verification that doesn't block
**Pages affectées:**
- deploy.sh: Simplified Git repository verification step
**Motivations:**
- SSH ControlMaster connection errors were causing deployment failures
- Connection reset errors were not handled properly
- No retry mechanism for failed SSH connections
**Root causes:**
- SSH ControlMaster socket could become stale or be closed prematurely
- No validation of connection before use
- No cleanup of dead connections
- Silent failures in conditional checks
**Correctifs:**
- Added connection validation before each SSH command
- Implemented automatic cleanup of dead SSH connections
- Added retry mechanism (up to 3 attempts) with connection cleanup
- Enhanced SSH options for better connection stability (ConnectTimeout, ServerAliveInterval, ServerAliveCountMax)
- Improved error handling in Git repository verification step with explicit error detection and recovery
**Evolutions:**
- Enhanced SSH connection management with robust error handling
- Better error messages to distinguish connection errors from other failures
**Pages affectées:**
- deploy.sh: Enhanced ssh_exec() function, added helper functions, improved error handling
- fixKnowledge/ssh-connection-errors-deployment.md: Documentation of the problem, root cause, and solution