From a4adf9a39855e359dd5c057362b13fa8f4ad2803 Mon Sep 17 00:00:00 2001 From: Developer Date: Mon, 20 Apr 2026 22:01:38 -0400 Subject: [PATCH] FIX: Add timeouts to MySQL detection to prevent hanging The calculate_server_memory_capacity() function was hanging during optimization levels 1-4 because of unguarded MySQL queries. Fixed: 1. Added 2-second timeout to MySQL queries in detect_mysql_memory_usage() - Lines 1395-1396: buffer_pool_mb and max_connections queries - These would hang indefinitely if MySQL was slow or unresponsive 2. Added 5-second timeout to detect_mysql_memory_usage() call - Line 1008 in calculate_server_memory_capacity() - Prevents the entire function from blocking This allows optimization levels 1-5 to execute without hanging when MySQL is unavailable or slow to respond. --- lib/php-analyzer.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/php-analyzer.sh b/lib/php-analyzer.sh index 0873645..73f845f 100644 --- a/lib/php-analyzer.sh +++ b/lib/php-analyzer.sh @@ -1001,11 +1001,11 @@ calculate_server_memory_capacity() { done <<< "$user_domains" done <<< "$users" - # Add MySQL memory usage to total + # Add MySQL memory usage to total (with timeout to prevent hanging) local mysql_memory_mb=0 local mysql_status local mysql_info - mysql_info=$(detect_mysql_memory_usage 2>/dev/null) + mysql_info=$(timeout 5 detect_mysql_memory_usage 2>/dev/null) if [ $? -eq 0 ] && [ -n "$mysql_info" ]; then mysql_memory_mb=$(echo "$mysql_info" | cut -d'|' -f3 || echo "0") mysql_status=$(echo "$mysql_info" | cut -d'|' -f4) @@ -1391,9 +1391,9 @@ detect_mysql_memory_usage() { local max_connections=150 # Default if command -v mysql >/dev/null 2>&1; then - # Try to query MySQL directly - buffer_pool_mb=$(mysql -Nse "SELECT ROUND(@@innodb_buffer_pool_size/1024/1024)" 2>/dev/null || echo "0") - max_connections=$(mysql -Nse "SELECT @@max_connections" 2>/dev/null || echo "150") + # Try to query MySQL directly (with 2 second timeout to prevent hanging) + buffer_pool_mb=$(timeout 2 mysql -Nse "SELECT ROUND(@@innodb_buffer_pool_size/1024/1024)" 2>/dev/null || echo "0") + max_connections=$(timeout 2 mysql -Nse "SELECT @@max_connections" 2>/dev/null || echo "150") fi # If we couldn't get it from MySQL, try my.cnf