From 0559f2d66840515a5f6b8b2d0dce470c5f911962 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Tue, 10 Feb 2026 12:56:21 -0500 Subject: [PATCH] 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 https://code.lotusguild.org/LotusGuild/hwmonDaemon/issues/7 Co-Authored-By: Claude Opus 4.6 --- hwmonDaemon.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hwmonDaemon.py b/hwmonDaemon.py index 3a6ab26..c985e94 100644 --- a/hwmonDaemon.py +++ b/hwmonDaemon.py @@ -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