Add missing timeouts to all subprocess calls

Add timeout=30 to smartctl -i calls in _get_drive_details() and
_check_disk_firmware(), and dmidecode in _check_memory_usage().
Add TimeoutExpired handler in _check_disk_firmware(). Prevents
potential hangs when drives or system tools become unresponsive.

Resolves #9

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-10 12:57:17 -05:00
parent c7309663de
commit a3cf5a698f

View File

@@ -1051,7 +1051,8 @@ class SystemHealthMonitor:
['smartctl', '-i', device], ['smartctl', '-i', device],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
text=True text=True,
timeout=30
) )
# Check if smartctl failed completely # Check if smartctl failed completely
@@ -2065,7 +2066,8 @@ class SystemHealthMonitor:
['smartctl', '-i', device], ['smartctl', '-i', device],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
text=True text=True,
timeout=30
) )
model_line = None model_line = None
@@ -2105,6 +2107,8 @@ class SystemHealthMonitor:
logger.debug(f"Known issues: {firmware_info['known_issues']}") logger.debug(f"Known issues: {firmware_info['known_issues']}")
logger.debug("=== End Firmware Check ===\n") logger.debug("=== End Firmware Check ===\n")
except subprocess.TimeoutExpired:
logger.warning(f"smartctl -i timed out for {device}")
except Exception as e: except Exception as e:
firmware_info['known_issues'].append(f"Error checking firmware: {str(e)}") firmware_info['known_issues'].append(f"Error checking firmware: {str(e)}")
@@ -2813,7 +2817,8 @@ class SystemHealthMonitor:
['dmidecode', '--type', 'memory'], ['dmidecode', '--type', 'memory'],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
text=True text=True,
timeout=30
) )
if 'Error Correction Type: Multi-bit ECC' in result.stdout: if 'Error Correction Type: Multi-bit ECC' in result.stdout:
memory_health['has_ecc'] = True memory_health['has_ecc'] = True