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
1 change: 1 addition & 0 deletions plugins/inputs/logfile/tail/tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ func (tail *Tail) unreadByte() (err error) {
}

func (tail *Tail) ReleaseLine(line *Line) {
*line = Line{}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL: this won't go to the heap because the compiler is smart enough to not "escape" it

tail.linePool.Put(line)
Comment thread
duhminick marked this conversation as resolved.
}

Expand Down
9 changes: 6 additions & 3 deletions plugins/inputs/logfile/tail/tail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,13 @@ func TestLinePooling(t *testing.T) {
tail.ReleaseLine(line)
}

// Verify pool reuse by checking if we get an object with one of the lines
// Line object should be zeroed out because we released it
pooledLine := tail.linePool.Get().(*Line)
assert.Contains(t, []string{"line1", "line2", "line3"}, pooledLine.Text)
tail.linePool.Put(pooledLine)
assert.Empty(t, pooledLine.Text, "Pooled line should remain zeroed")
assert.Empty(t, pooledLine.Time, "Pooled line should remain zeroed")
assert.Empty(t, pooledLine.Err, "Pooled line should remain zeroed")
assert.Empty(t, pooledLine.Offset, "Pooled line should remain zeroed")
tail.ReleaseLine(pooledLine)
}

// TestConcurrentLinePoolAccess tests that the line pool is thread-safe
Expand Down
Loading