Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions plugins/inputs/tail/tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,16 +351,14 @@ func (t *Tail) cleanupUnusedTailers(currentFiles map[string]bool) error {
// We need to stop tailing it and remove it from our list
t.Log.Debugf("Removing tailer for %q as it's no longer in the glob pattern", file)

// Save the current offset for potential future use
if !t.Pipe {
offset, err := tailer.Tell()
if err == nil {
t.Log.Debugf("Recording offset %d for %q", offset, tailer.Filename)
t.offsets[tailer.Filename] = offset
} else {
t.Log.Errorf("Recording offset for %q: %s", tailer.Filename, err.Error())
}
}
// NOTE: We intentionally do NOT save the offset here because:
// 1. There's a data race in the tail library between Tell() and reopen()
// that could cause undefined behavior or incorrect offsets
// 2. Files removed from glob patterns are typically rotated logs that
// won't return with the same name
// 3. The Stop() method will save offsets safely when the plugin stops
// This trade-off prioritizes stability over rare edge cases where a
// file temporarily doesn't match the glob and returns later.
Comment thread
srebhan marked this conversation as resolved.
Outdated

// Stop the tailer
err := tailer.Stop()
Expand Down
1 change: 0 additions & 1 deletion plugins/inputs/tail/tail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,6 @@ func TestTailNoLeak(t *testing.T) {
// TestTailCleanupUnusedTailers tests the fix for file descriptor leaks
// by ensuring tailers for files that no longer match the glob pattern are cleaned up
func TestTailCleanupUnusedTailers(t *testing.T) {
t.Skip("Test disabled due to data race - see issue #[17571] for fix progress")
// Create a temp directory for our test files
tempDir := t.TempDir()

Expand Down
Loading