mozilla-services/heka — pull request #1114 by validname (2014-10-08 08:07:24+00:00)
Title: LogStreamer reader: reset priorEOF after successfull read

I think there is a mistake in logic of readBytes() function.

1. Suppose we got an EOF at l.reader.Read(p) (line 528), at first time (l.priorEOF=false). We pass through lines 535 to 560 and set l.priorEOF=true at line 564. Then trying to read file further l.Read(p) and return at line 568.
2. At second time and if we successfully read we just returns. l.priorEOF remains with 'true'. And that will be other times, while we can read the file.
3. Suppose, we got EOF again. We passing to line 571. If we don't have new file - OK, just return.
4. So only If we had new file and succesfully opened it we set l.priorEOF to 'false'. This is the only case of resetting l.priorEOF

I think, we should reset l.priorEOF after successfull reading.

I suddenly discovered this debugging how LogStreamer determines rotating files. My debug was very simple: I just copied nearest comments to log.Printf(). I was surprised, when I saw only two patterns of running code:

first pattern: when reading file was just increased:
2014/10/07 23:42:15 [DEBUG] LogStreamer/readBytes(): [/data/logs/error.log, 16] we had an EOF last time, we check for a new file before trying to read again
2014/10/07 23:42:15 [DEBUG] LogStreamer/readBytes(): [/data/logs/error.log, 16] read 3398 bytes

And second one: when there is no new bytes:
2014/10/07 23:42:15 [DEBUG] LogStreamer/readBytes(): [/data/logs/error.log, 47] we had an EOF last time, we check for a new file before trying to read again
2014/10/07 23:42:15 [DEBUG] LogStreamer/readBytes(): [/data/logs/error.log, 47] it must be an EOF
2014/10/07 23:42:15 [DEBUG] LogStreamer/readBytes(): [/data/logs/error.log, 47] We don't have a newer file, so we will keep checking for a newer file and return the EOF to now indicating we can proceed no further

And I got message "Record that we got an EOF' (from line 561) only twice: when hekad was started and when reading file was rotated.