hpcloud / tail

Go package for reading from continously updated files (tail -f)
MIT License
2.71k stars 503 forks source link

Issue on Stop Tailing #47

Closed marioffmarques closed 8 years ago

marioffmarques commented 9 years ago

Hello,

I'm using this func err := t.Stop()

to stop tailing activity on a file, however this not stops the tailing. Is this the correct aproach to stop tailing ? If not, how can I achieve my goal ? Thanks in advance

Nino-K commented 9 years ago

@marioffmarques Can you paste a bit of your code so we can see how t.Stop() is being called? Generally you want to read lines while you are subscribed to the Lines chan and have some sort of stop chan that stops the tailing process. e.g.

stopCh := make(chan bool)

for {
        select {
        case line, ok := <-t.Lines:
            if !ok {
                err = t.Wait()
                break 
            }
            // do something with the line 
        case <-stopCh:
            err = t.Stop()
            break 
        }
    }
marioffmarques commented 9 years ago

Firstly, thanks for the reply. For reading lines, I have this block of code:

    tailHandle, err := tail.TailFile(filePath, tail.Config{Follow: true})
    for line := range tailHandle.Lines {
        fmt.Println("Readed: " + line.Text)
    }

And for stop the tailing I use this: tailHandle.Stop()

Using your aproch I get a fatal error: all goroutines are asleep - deadlock!

sparrc commented 8 years ago

@marioffmarques this indicates an issue in your code handling goroutines, this is not an issue with the tail package

Nino-K commented 8 years ago

@marioffmarques going to close this issue, as it seems not related to tail.