Fix file locking race condition in SMART trend analysis
Check both file existence AND size > 0 before opening in r+ mode. Previously, an empty file (0 bytes) would be opened in r+ mode, causing json.load() to fail on the empty content. Resolves #7 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -783,7 +783,10 @@ class SystemHealthMonitor:
|
||||
|
||||
# Load historical data with file locking
|
||||
history = []
|
||||
file_mode = 'r+' if os.path.exists(historical_file) else 'w+'
|
||||
if os.path.exists(historical_file) and os.path.getsize(historical_file) > 0:
|
||||
file_mode = 'r+'
|
||||
else:
|
||||
file_mode = 'w+'
|
||||
|
||||
with open(historical_file, file_mode) as f:
|
||||
# Acquire exclusive lock
|
||||
|
||||
Reference in New Issue
Block a user