Skip to content

Commit

Permalink
adding a Size() function to get the length of the current file being …
Browse files Browse the repository at this point in the history
…tailed in bytes
  • Loading branch information
slim-bean committed Oct 23, 2019
1 parent 5ab7a9e commit 4de054d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,17 @@ func (tail *Tail) Tell() (offset int64, err error) {
return
}

// Size returns the length in bytes of the file being tailed,
// or 0 with an error if there was an error Stat'ing the file.
func (tail *Tail) Size() (size int64, err error) {

This comment has been minimized.

Copy link
@pstibrany

pstibrany Nov 19, 2019

Member

This method introduced race condition into the library. It reads tail.file, which can at the same time be modified by goroutine started in TailFile method (when reopening the file). (See failing tests in grafana/loki#1283)

fi, err := tail.file.Stat()
if err != nil {
return
}
size = fi.Size()
return
}

// Stop stops the tailing activity.
func (tail *Tail) Stop() error {
tail.Kill(nil)
Expand Down

0 comments on commit 4de054d

Please sign in to comment.