Skip to content

fix(file source): avoid remove_after deleting files with buffered partial lines or oversized discards - #27317

Draft
lukesteensen wants to merge 1 commit into
masterfrom
fix/file-source-remove-after-active-files
Draft

lukesteensen wants to merge 1 commit into
masterfrom
fix/file-source-remove-after-active-files

Conversation

@lukesteensen

Copy link
Copy Markdown
Member

Summary

Fixes two related bugs where remove_after_secs deletes an active file prematurely:

  1. Buffered partial line silently dropped: When bytes_read == 0 and watcher.last_read_success().elapsed() >= remove_after, FileServer unlinked the file and marked the watcher dead without checking whether FileWatcher::buf still held an incomplete partial line awaiting its delimiter — silently discarding the buffered bytes.
  2. Oversized line discard treated as idle & FileLineTooLong dropped: When FileWatcher::read_line discarded a line exceeding max_line_bytes and then hit EOF (raw_line: None), FileServer's while let Ok(RawLineResult { raw_line: Some(..), .. }) loop exited without emitting FileLineTooLong, did not count the discard as read progress, and allowed remove_after to immediately delete the file.

This PR adds FileWatcher::has_buffered_data(), updates last_read_success when oversized lines are discarded, emits FileLineTooLong even when raw_line is None, and skips remove_after deletion while partial data is buffered or an oversized line was just discarded.

Vector configuration

N/A

How did you test this PR?

  • Added unit tests in lib/file-source/src/file_server.rs:
    • remove_after_zero_does_not_delete_file_with_buffered_partial_line
    • remove_after_does_not_delete_file_on_oversized_line_discard
  • cargo clippy -p file-source --all-targets -- -D warnings
  • cargo test -p file-source --lib -- remove_after_

Does this PR include user facing changes?

  • Yes. Bug fix preventing premature file deletion under remove_after_secs and emitting FileLineTooLong when no normal line follows (changelog fragment to be added before marking ready for review).
  • No. A maintainer will apply the no-changelog label to this PR.

This branch has not been deployed

No deployments
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