Race Condition in History File Handling #7

Open
opened 2026-02-02 14:45:34 -05:00 by jared · 0 comments
Owner

The file locking in _analyze_smart_trends opens with mode 'r+' or 'w+' but doesn't handle the case where the file is created empty:

file_mode = 'r+' if os.path.exists(historical_file) else 'w+'

...

if os.path.getsize(historical_file) > 0: # This check happens AFTER opening

Fix:

Check file existence and size BEFORE opening

if os.path.exists(historical_file) and os.path.getsize(historical_file) > 0:
file_mode = 'r+'
else:
file_mode = 'w+'

The file locking in _analyze_smart_trends opens with mode 'r+' or 'w+' but doesn't handle the case where the file is created empty: file_mode = 'r+' if os.path.exists(historical_file) else 'w+' # ... if os.path.getsize(historical_file) > 0: # This check happens AFTER opening Fix: # Check file existence and size BEFORE opening if os.path.exists(historical_file) and os.path.getsize(historical_file) > 0: file_mode = 'r+' else: file_mode = 'w+'
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: LotusGuild/hwmonDaemon#7