go-tail
go-tail copied to clipboard
reopen fails to reopen
repro:
touch test.log
./go-tail -F ./test.log &
date > test.log
Fri Sep 15 13:26:55 EDT 2017
mv test.log test.log0 ; touch test.log
open ./test.log: no such file or directory
date >> test.log
# tail is hung/crashed, doesn't exit
Expected: no error, and date to be outputted twice.
This error is related to this lines of code: https://github.com/papertrail/go-tail/blob/master/follower/follower.go#L202-L210
Basically it detects the error but it doesn't do anything about it
I was able to fix this by adding a hack (sleep) after line 204:
default: if !t.config.Reopen { return nil } time.Sleep(30 * time.Second) if err := t.rewatch(); err != nil { return err }
This way if the file is moved (and then moved back) in 10s it gets reopened.