From 46467e39c2d9922c27370cac8a4852662469749a Mon Sep 17 00:00:00 2001 From: David Crawshaw Date: Wed, 22 Feb 2023 21:24:45 -0800 Subject: [PATCH] logtail: allow multiple calls to Shutdown Signed-off-by: David Crawshaw --- logtail/logtail.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/logtail/logtail.go b/logtail/logtail.go index 4762d3611..8979c914f 100644 --- a/logtail/logtail.go +++ b/logtail/logtail.go @@ -198,8 +198,9 @@ type Logger struct { procSequence uint64 flushTimer *time.Timer // used when flushDelay is >0 - shutdownStart chan struct{} // closed when shutdown begins - shutdownDone chan struct{} // closed when shutdown complete + shutdownStartMu sync.Mutex // guards the closing of shutdownStart + shutdownStart chan struct{} // closed when shutdown begins + shutdownDone chan struct{} // closed when shutdown complete } // SetVerbosityLevel controls the verbosity level that should be @@ -240,7 +241,16 @@ func (l *Logger) Shutdown(ctx context.Context) error { close(done) }() + l.shutdownStartMu.Lock() + select { + case <-l.shutdownStart: + l.shutdownStartMu.Unlock() + return nil + default: + } close(l.shutdownStart) + l.shutdownStartMu.Unlock() + io.WriteString(l, "logger closing down\n") <-done