Skip to content

BUG: make log rotation safe across Windows processes - #5303

Merged
qinxuye merged 2 commits into
xorbitsai:mainfrom
Ricardo-M-L:fix/windows-safe-log-rotation
Oct 7, 2026
Merged

qinxuye merged 2 commits into
xorbitsai:mainfrom
Ricardo-M-L:fix/windows-safe-log-rotation

Conversation

@Ricardo-M-L

@Ricardo-M-L Ricardo-M-L commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • use msvcrt.locking on Windows while retaining fcntl.flock on POSIX
  • serialize Windows writes with rollover so no record can land between the copy and truncate fallback steps
  • close the lock file if native lock acquisition fails
  • persist a rotation generation and timed-rollover marker so waiting processes do not rotate or overwrite the same archive again
  • share the coordination logic across size, timed, and combined handlers

Fixes #5284.

Validation

  • xinference/deploy/test/test_log_rotation.py: 37 passed
  • repository pre-commit hooks: Black, Ruff, isort, mypy, codespell, whitespace checks all passed
  • rebased onto current upstream/main

The regression coverage includes a deterministic concurrent-write test that pauses after the Windows fallback copy, verifies a sibling writer blocks, and confirms the record is preserved after truncation. Windows locking behavior is simulated on macOS; the repository Windows CI job provides the native-platform check.

@XprobeBot XprobeBot added the bug Something isn't working label Aug 8, 2026
@XprobeBot XprobeBot added this to the v3.x milestone Aug 8, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces cross-platform, cross-process log rotation safety by implementing a shared _SafeFileRotationMixin that uses platform-native file locking (msvcrt on Windows and fcntl on Unix) and tracks rotation state via a shared lock file. It updates the rotating file handlers to inherit from this mixin and adds comprehensive unit tests to verify the Windows fallback and rotation coordination. The feedback highlights a potential file descriptor leak in _acquire_rotation_lock if the locking mechanism raises an exception, suggesting wrapping the lock acquisition in a try...except block to ensure the file descriptor is closed.

Comment thread xinference/deploy/utils.py
@Ricardo-M-L

Copy link
Copy Markdown
Contributor Author

Friendly ping - this PR makes log rotation safe across Windows processes. Would appreciate a review. Thanks!

@qinxuye qinxuye left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also address the unresolved Gemini review comment: _acquire_rotation_lock() must close lock_fd if msvcrt.locking() or fcntl.flock() raises.

Comment thread xinference/deploy/utils.py
@Ricardo-M-L
Ricardo-M-L force-pushed the fix/windows-safe-log-rotation branch from a04459a to ec4dd40 Compare October 7, 2026 08:19

@qinxuye qinxuye left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Verified both previous findings are fixed: failed lock acquisition closes the descriptor, and Windows writes share the rotation lock across copy/truncate. Both threads are resolved. All 37 focused log-rotation tests passed locally, including the simulated Windows concurrent-write regression; CI is green.

@qinxuye
qinxuye merged commit 79af8dd into xorbitsai:main Oct 7, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Windows: log rotation crashes with WinError 32 because fcntl-based cross-process lock is a no-op

3 participants