Skip to content

fix(octop): guard Path.stat() with OSError in server log rotation and purge - #2669

Closed
TrueFurina wants to merge 1 commit into
TencentCloud:mainfrom
TrueFurina:r79-server-stat-guard
Closed

TrueFurina wants to merge 1 commit into
TencentCloud:mainfrom
TrueFurina:r79-server-stat-guard

Conversation

@TrueFurina

Copy link
Copy Markdown

Summary

Wrap two bare Path.stat() calls in server.py log management functions with try/except OSError. One file, one commit.

Changes

Call site Location On OSError
p.stat().st_mtime max() key _gzip_oldest_rotated_logs() Return early, skip compression cycle
entry.stat().st_mtime comparison _purge_stale_logs() Skip that entry (continue loop)

Context

Both operate on rotated log files under the server log directory. The directory already passes is_dir()/iterdir() guards from round 72, but individual log files can still be unreadable during stat() — Windows Defender/antivirus commonly locks recently-written log files briefly after rotation. The stale-log unlink() at L269 already uses suppress(OSError); this fix makes the preceding stat() equally defensive.

Pattern

Continues the Path.stat() defensive sweep. Remaining targets: postgres_storage.py, slim.py, backup.py, profile_avatar.py, manage_skills.py, skill_package_store.py.

… purge

Two bare Path.stat() calls in server.py on rotated log files. On Windows, the log directory passes is_dir() but individual entries can still raise PermissionError from antivirus locks or ACL restrictions during stat().

1. _gzip_oldest_rotated_logs(): max() key function p.stat().st_mtime to find the oldest log to keep. On OSError bail out and skip compression (safer than crashing).

2. _purge_stale_logs(): entry.stat().st_mtime comparison with cutoff. On OSError skip that entry (continue loop). Note the subsequent entry.unlink() already uses suppress(OSError).
@jubaoliang jubaoliang closed this Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants