Skip to content

fix(octop): guard log_dir.iterdir() with OSError in server log helpers - #2657

Closed
TrueFurina wants to merge 1 commit into
TencentCloud:mainfrom
TrueFurina:r72-server-log-iterdir
Closed

TrueFurina wants to merge 1 commit into
TencentCloud:mainfrom
TrueFurina:r72-server-log-iterdir

Conversation

@TrueFurina

Copy link
Copy Markdown

Summary

Wrap two bare log_dir.iterdir() calls in src/octop/infra/server.py with ry/except OSError.

Problem

Both _migrate_legacy_rotated_logs() and _iter_rotated_logs() gate on log_dir.is_dir() before iterating. On Windows, is_dir() only checks that the directory entry exists — it does not guarantee read permission. ACLs, antivirus locks, or a handle held by an external log viewer can all raise PermissionError (a subclass of OSError) the moment iterdir() runs. An unhandled exception here would crash server startup or the rotated-log enumeration path.

Fix

  • _migrate_legacy_rotated_logs(): wrap list(log_dir.iterdir()) in try/except OSError, return early on failure.
  • _iter_rotated_logs(): same pattern — degrade to an empty generator on failure.

This is part of the broader defensive-itdir pattern also applied to skill_package_store.py, workspace_catalog.py, and the harness CLI commands (PR #191, #192, #193).

Both _migrate_legacy_rotated_logs() and _iter_rotated_logs() check log_dir.is_dir() before calling iterdir(), but is_dir() only verifies the directory entry exists, not that the process has read permission. On Windows the log directory can be ACL-restricted or locked by an antivirus or log viewer process, causing PermissionError to crash the server startup or log-migration path. Wrap each iterdir() in try/except OSError and degrade gracefully (return early / empty generator).
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