Skip to content

fix: clear stale tail buffer after log rotation#315

Open
immanuwell wants to merge 1 commit into
coroot:mainfrom
immanuwell:fix-tail-reader-rotation-buffer
Open

fix: clear stale tail buffer after log rotation#315
immanuwell wants to merge 1 commit into
coroot:mainfrom
immanuwell:fix-tail-reader-rotation-buffer

Conversation

@immanuwell
Copy link
Copy Markdown

If a tailed file ends with a partial line and gets rotated or recreated, the old prefix leaks into the first line of the new file. You get stale-prefixfresh line. Pretty easy to hit in the wild with container log rotation.

This clears the buffered prefix on rotate, truncate, and recreate. Normal append still keeps partial lines, so that bit stays the same.

Repro

  1. Start TailReader
  2. Write stale-prefix without \n
  3. Rotate or recreate the file
  4. Write fresh line\n
  5. Before: stale-prefixfresh line
  6. After: fresh line

Tested with go test tail_reader.go tail_reader_test.go -run TestTailReader -count=3

@def
Copy link
Copy Markdown
Member

def commented May 29, 2026

@immanuwell could you please clarify whether you've actually encountered this issue in your environment?

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