logtail: allow multiple calls to Shutdown

Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
pull/7368/head
David Crawshaw 2 years ago
parent daa2f1c66e
commit 46467e39c2

@ -198,6 +198,7 @@ type Logger struct {
procSequence uint64 procSequence uint64
flushTimer *time.Timer // used when flushDelay is >0 flushTimer *time.Timer // used when flushDelay is >0
shutdownStartMu sync.Mutex // guards the closing of shutdownStart
shutdownStart chan struct{} // closed when shutdown begins shutdownStart chan struct{} // closed when shutdown begins
shutdownDone chan struct{} // closed when shutdown complete shutdownDone chan struct{} // closed when shutdown complete
} }
@ -240,7 +241,16 @@ func (l *Logger) Shutdown(ctx context.Context) error {
close(done) close(done)
}() }()
l.shutdownStartMu.Lock()
select {
case <-l.shutdownStart:
l.shutdownStartMu.Unlock()
return nil
default:
}
close(l.shutdownStart) close(l.shutdownStart)
l.shutdownStartMu.Unlock()
io.WriteString(l, "logger closing down\n") io.WriteString(l, "logger closing down\n")
<-done <-done

Loading…
Cancel
Save