hpcloud / tail

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

Don't block on tail.Lines on shutdown #129

Open lmars opened 6 years ago

lmars commented 6 years ago

It is quite typical to do something like the following to cancel tailing a file:

go func() {
    defer t.Stop()
    for {
        select {
        case line, ok := t.Lines:
            // ...
        case <-ctx.Done():
            return
    }
}

but then this means after the context is cancelled, there is no reader of the Tail.Lines channel and the library will block.

This change modifies the library to always select on Tail.Dying() when sending to Tail.Lines in case the user has stopped receiving and stopped the tailing.