From 3bc7ab94bf698a6affc97b166a36ac8a326a590c Mon Sep 17 00:00:00 2001 From: Munir Khakhi Date: Wed, 24 Dec 2025 17:44:51 +0530 Subject: [PATCH] bug: fix tail while empty line #191 --- tail.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tail.go b/tail.go index 6037aaa..4538038 100644 --- a/tail.go +++ b/tail.go @@ -49,14 +49,17 @@ func tailFile(ctx context.Context, file string, poll bool, dest *os.File) { return // get the next log line and echo it out case line := <-t.Lines: - if t.Err() != nil { - log.Printf("Warning: unable to tail %s: %s", file, t.Err()) - errCount++ - if errCount > 30 { - log.Fatalf("Logged %d consecutive errors while tailing. Exiting", errCount) + if line == nil { + // Check if there's an actual error + if err := t.Err(); err != nil { + log.Printf("Warning: unable to tail %s: %s", file, err) + errCount++ + if errCount > 30 { + log.Fatalf("Logged %d consecutive errors while tailing. Exiting", errCount) + } + time.Sleep(2 * time.Second) // Sleep for 2 seconds before retrying + continue } - time.Sleep(2 * time.Second) // Sleep for 2 seconds before retrying - } else if line == nil { return } else { fmt.Fprintln(dest, line.Text)