Skip to content

Commit

Permalink
Merge pull request #20 from naver/fix-freezed-tailer
Browse files Browse the repository at this point in the history
fix the log tailer to ensure it drains all remaining logs without waiting
  • Loading branch information
sharkpc138 authored Dec 12, 2024
2 parents 1bf0068 + f404006 commit d0df58b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
7 changes: 4 additions & 3 deletions pkg/lobster/tailer/tail/tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type Config struct {
type Tail struct {
Filename string
Lines chan *Line
IsSending bool
IsTailing bool
Config

file *os.File
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions pkg/lobster/tailer/tailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
const (
statusRunning status = 1
statusIdle status = 2
drainWait = time.Millisecond
)

type status int
Expand Down Expand Up @@ -178,15 +177,13 @@ func (t *Tailer) doStop() {
func (t *Tailer) drain() {
t.tail.Kill(nil)

time.Sleep(drainWait)

select {
case <-t.LogChan:
default:
close(t.LogChan)
}

for t.tail.IsSending {
for t.tail.IsTailing {
select {
case <-t.tail.Lines:
default:
Expand Down

0 comments on commit d0df58b

Please sign in to comment.