fix: initialize log_written from file size to prevent 2x cap drift#16
Open
ricardovfreixo wants to merge 1 commit intomobydeck:mainfrom
Open
fix: initialize log_written from file size to prevent 2x cap drift#16ricardovfreixo wants to merge 1 commit intomobydeck:mainfrom
ricardovfreixo wants to merge 1 commit intomobydeck:mainfrom
Conversation
log_written tracked bytes since last rotation, not actual file size. After open_log(), the file could already hold log_max_size bytes but log_written started at 0, so another log_max_size was written before rotation triggered. Initialize log_written from the fd position after rotate_log() so the counter reflects reality.
010e671 to
a6f6c7f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The on-disk session log can grow to twice the configured
-Ccap before rotation kicks in.Root cause
log_writtentracks bytes written since the last rotation, not the actual file size. Afteropen_log(), the file can already contain up tolog_max_sizebytes (trimmed byrotate_log()), butlog_writtenis initialized to 0. Rotation only triggers whenlog_written >= log_max_size, so another fulllog_max_sizeof data is appended before the check fires.Fix
Initialize
log_writtenfrom the fd position afterrotate_log()inopen_log(), so the counter reflects the actual file size from the start:Single line change, no new syscall overhead (piggybacks on the position
rotate_log()already established via its finallseek(log_fd, 0, SEEK_END)).Test plan
atch new test -C 64k -- sh -c 'cat /dev/urandom | base64'ls -la ~/.cache/atch/test.log— should be at most ~64KB (plus one write batch), not ~128KBatch testshows recent output, not truncated mid-sequencemake clean && make— no new warnings