Skip to content

fix: prevent sparse gaps after cross-process log rotation - #23

Open
Windsland52 wants to merge 1 commit into
masterfrom
fix/logger-cross-process-rotation
Open

fix: prevent sparse gaps after cross-process log rotation#23
Windsland52 wants to merge 1 commit into
masterfrom
fix/logger-cross-process-rotation

Conversation

@Windsland52

@Windsland52 Windsland52 commented Aug 28, 2026

Copy link
Copy Markdown
Member

Summary

  • keep every long-lived logger stream in append mode
  • truncate a rotated log with a separate short-lived stream before reopening it
  • prevent stale file offsets from creating large NUL-filled gaps when multiple processes share a log directory

Cause

After rotation, Logger previously reopened maafw.log with a long-lived truncating stream. If another process later rotated or truncated the same file, that stream retained its old file offset. Its next write could therefore create a large zero-filled gap, which then caused repeated oversized backups.

Validation

  • compiled the modified Logger.cpp with MSVC in C++20 mode
  • ran a two-process regression scenario: seed a 17 MiB log, rotate it, truncate the active log from a child process, then write again from the original logger
  • resulting active log contained no NUL bytes (size=92, has_zero=false)
  • clang-format --dry-run --Werror passed
  • git diff --check passed

Sourcery 总结

通过将截断操作与长生命周期的日志写入分离,防止跨进程轮换后出现稀疏的日志空洞。

Bug 修复:

  • 防止跨进程日志轮换在活动日志文件中创建稀疏的、填充 NUL 的空洞。

改进:

  • 让长生命周期的日志记录器流保持追加模式,同时在重新打开期间通过短生命周期的流执行截断。
Original summary in English

Summary by Sourcery

Prevent sparse log gaps after cross-process rotation by separating truncation from long-lived log writing.

Bug Fixes:

  • Prevent cross-process log rotation from creating sparse, NUL-filled gaps in active log files.

Enhancements:

  • Keep long-lived logger streams in append mode while performing truncation through a short-lived stream during reopening.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

嗨——我已经审阅了你的更改,看起来很棒!


Sourcery 对开源项目免费——如果你喜欢我们的评审,请考虑分享它们 ✨
请帮助我变得更有用!请在每条评论上点击 👍 或 👎,我会利用这些反馈来改进评审。
Original comment in English

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Windsland52

Copy link
Copy Markdown
Member Author

cc @MistEO

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.

1 participant