Skip to content

fix: flush accumulated buffer on EOF without trailing newline#976

Open
Vitalymt wants to merge 1 commit into
ozontech:masterfrom
Vitalymt:fix/eof-without-newline-drop
Open

fix: flush accumulated buffer on EOF without trailing newline#976
Vitalymt wants to merge 1 commit into
ozontech:masterfrom
Vitalymt:fix/eof-without-newline-drop

Conversation

@Vitalymt
Copy link
Copy Markdown

Problem

When a file doesn't end with a newline character, the last line is silently dropped.

The read loop in worker.go accumulates data in accumBuf until it finds a \n. At EOF, the remaining data is saved to job.tail without ever being emitted through controller.In(). If the file is never written to again, that data is lost permanently.

Steps to reproduce:

  1. Create a file with content that doesn't end with \n: echo -n "hello" > /tmp/test.txt
  2. Configure file.d to read this file
  3. The "hello" event is never emitted

Fix

Emit accumBuf as a final event before calling processEOF when EOF is reached and the buffer is non-empty. Clear both accumBuf and job.tail afterward to prevent re-emission on file truncation.

Changes:

  • plugin/input/file/worker.go: +8 lines — flush buffer on EOF
  • plugin/input/file/worker_test.go: updated existing test expectation + added multi-line test case

Fixes #912

When a file doesn't end with a newline character, the last line is
silently dropped. The read loop accumulates data in accumBuf until it
finds a '\n', but at EOF the remaining data is saved to job.tail
without ever being emitted through controller.In().

If the file is never written to again, that data is lost permanently.

Fix: emit accumBuf as a final event before calling processEOF when
EOF is reached and the buffer is non-empty. Clear both accumBuf and
job.tail afterward to prevent re-emission on file truncation.

Fixes ozontech#912
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.

Bug: skips last line without new line

1 participant