Skip to content

Commit

Permalink
Merge pull request #25 from naver/fix-freezed-tailer
Browse files Browse the repository at this point in the history
fix variable to use atomic
  • Loading branch information
sharkpc138 authored Dec 13, 2024
2 parents 8b2b03e + 1e0029f commit cd34550
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
14 changes: 7 additions & 7 deletions pkg/lobster/tailer/tail/tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"strings"
"sync"
"sync/atomic"
"time"

"github.com/golang/glog"
Expand Down Expand Up @@ -77,7 +78,7 @@ type Config struct {
type Tail struct {
Filename string
Lines chan *Line
IsTailing bool
IsTailing int32
Config

file *os.File
Expand Down Expand Up @@ -108,9 +109,10 @@ func TailFile(filename string, config Config) (*Tail, error) {
}

t := &Tail{
Filename: filename,
Lines: make(chan *Line),
Config: config,
Filename: filename,
Lines: make(chan *Line),
Config: config,
IsTailing: 1,
}

// when Logger was not specified in config, use default logger
Expand Down Expand Up @@ -233,12 +235,10 @@ func (tail *Tail) readLine() (string, error) {
}

func (tail *Tail) tailFileSync() {
defer func() { tail.IsTailing = false }()
defer func() { atomic.StoreInt32(&tail.IsTailing, 0) }()
defer tail.Done()
defer tail.close()

tail.IsTailing = true

if !tail.MustExist {
// deferred first open.
err := tail.reopen()
Expand Down
3 changes: 2 additions & 1 deletion pkg/lobster/tailer/tailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"log"
"os"
"sync"
"sync/atomic"
"time"

"github.com/golang/glog"
Expand Down Expand Up @@ -183,7 +184,7 @@ func (t *Tailer) drain() {
close(t.LogChan)
}

for t.tail.IsTailing {
for atomic.LoadInt32(&t.tail.IsTailing) == 1 {
select {
case <-t.tail.Lines:
default:
Expand Down

0 comments on commit cd34550

Please sign in to comment.