From 1aa3d0d5f35896984d6942017ba26e1e08f4fddd Mon Sep 17 00:00:00 2001 From: sharkpc138 Date: Wed, 11 Dec 2024 14:11:43 +0900 Subject: [PATCH 1/2] fix the log tailer to ensure it drains all remaining logs without waiting --- pkg/lobster/tailer/tail/tail.go | 7 ++++--- pkg/lobster/tailer/tailer.go | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/lobster/tailer/tail/tail.go b/pkg/lobster/tailer/tail/tail.go index 321b7b0..a7d22e9 100644 --- a/pkg/lobster/tailer/tail/tail.go +++ b/pkg/lobster/tailer/tail/tail.go @@ -77,7 +77,7 @@ type Config struct { type Tail struct { Filename string Lines chan *Line - IsSending bool + IsTailing bool Config file *os.File @@ -233,9 +233,12 @@ func (tail *Tail) readLine() (string, error) { } func (tail *Tail) tailFileSync() { + defer func() { tail.IsTailing = false }() defer tail.Done() defer tail.close() + tail.IsTailing = true + if !tail.MustExist { // deferred first open. err := tail.reopen() @@ -434,8 +437,6 @@ func (tail *Tail) sendLine(line string) bool { now := time.Now() lines := []string{line} - tail.IsSending = true - defer func() { tail.IsSending = false }() // Split longer lines if tail.MaxLineSize > 0 && len(line) > tail.MaxLineSize { lines = util.PartitionString(line, tail.MaxLineSize) diff --git a/pkg/lobster/tailer/tailer.go b/pkg/lobster/tailer/tailer.go index 43165c2..55d3d40 100644 --- a/pkg/lobster/tailer/tailer.go +++ b/pkg/lobster/tailer/tailer.go @@ -186,7 +186,7 @@ func (t *Tailer) drain() { close(t.LogChan) } - for t.tail.IsSending { + for t.tail.IsTailing { select { case <-t.tail.Lines: default: From f404006aef71ca73290a3ab8f75a316bff2b3eaa Mon Sep 17 00:00:00 2001 From: sharkpc138 Date: Wed, 11 Dec 2024 14:36:12 +0900 Subject: [PATCH 2/2] remove drain wait seconds --- pkg/lobster/tailer/tailer.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/pkg/lobster/tailer/tailer.go b/pkg/lobster/tailer/tailer.go index 55d3d40..f5c405f 100644 --- a/pkg/lobster/tailer/tailer.go +++ b/pkg/lobster/tailer/tailer.go @@ -33,7 +33,6 @@ import ( const ( statusRunning status = 1 statusIdle status = 2 - drainWait = time.Millisecond ) type status int @@ -178,8 +177,6 @@ func (t *Tailer) doStop() { func (t *Tailer) drain() { t.tail.Kill(nil) - time.Sleep(drainWait) - select { case <-t.LogChan: default: