hpcloud / tail

Go package for reading from continously updated files (tail -f)
MIT License
2.71k stars 503 forks source link

Is the log file guaranteed to be read until the end before being reopened? #127

Open Minnozz opened 7 years ago

Minnozz commented 7 years ago

I was wondering if the log file that is begin followed (Follow: true, ReOpen: true) will be read until the end when it is moved and recreated. I can imagine a race condition where a line is written to the log file just before the file is rotated, and the new log file is openend before the old one has been read until the end.

chrisleavoy commented 7 years ago

i just confirmed this is actually a bug. It doesn't finish reading the renamed file before reopening the new file. I say this is a bug because it claims to follow BSD tail, which doesn't suffer from this issue.

ahrtr commented 5 years ago

Indeed some log entries may be lost when the file is rotated, but the BSD tail has the same issue.

It's a tradeoff. If you just use the logs to do some statistics analysis, then I think it's acceptable.