-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This fixes a couple of race conditions in the tail library, combining the ideas of nxadm/tail#70 and nxadm/tail#71. - Currently when StopAtEOF is called, and we previously encountered an EOF already, we stop reading the file immediately. However when tailing a file, new data might have become available in the meantime, before the StopAtEOF is called. The watcher might however not have notified us about that yet. Instead of exiting immediately if that happens, and leaving the data that's already in the file unread, continue iterating until we get the next EOF, as we can be reasonably sure that that's the EOF the user meant to stop at, making sure to read all the data that has been written by the time StopAtEOF is called. - When a StopAtEOF() is called the code should continue to send all lines to the Lines channel. The issue here is if the caller is not ready to receive a new line the code blocks as it is using a unbuffered channel. However <-tail.Dying() would return in this case so the line was skipped. This means that the caller did not get all lines until EOF. Now we still want to skip in case any other reason for kill was given therefore add special logic to only not read the Dying channel on the EOF case. The one downside is that StopAtEOF() could block forever if the caller never reads new Lines but this seems logical to me. If the caller wants to wait for EOF but never reads remaining Lines this would be a bug on their end. Co-authored-by: Paul Holzinger <[email protected]>
- Loading branch information
Showing
2 changed files
with
74 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters