mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-05 01:17:10 +02:00
Fix double close in logger
This commit is contained in:
parent
568d064089
commit
e912f2d7c0
@ -44,11 +44,12 @@ var levelStrings = map[Level]string{
|
|||||||
|
|
||||||
// Logger is a high-performance, non-blocking logger
|
// Logger is a high-performance, non-blocking logger
|
||||||
type Logger struct {
|
type Logger struct {
|
||||||
output io.Writer
|
output io.Writer
|
||||||
level atomic.Uint32
|
level atomic.Uint32
|
||||||
buffer *ringBuffer
|
buffer *ringBuffer
|
||||||
shutdown chan struct{}
|
shutdown chan struct{}
|
||||||
wg sync.WaitGroup
|
closeOnce sync.Once
|
||||||
|
wg sync.WaitGroup
|
||||||
|
|
||||||
// Reusable buffer pool for formatting messages
|
// Reusable buffer pool for formatting messages
|
||||||
bufPool sync.Pool
|
bufPool sync.Pool
|
||||||
@ -170,9 +171,12 @@ func (l *Logger) worker() {
|
|||||||
|
|
||||||
// Stop gracefully shuts down the logger
|
// Stop gracefully shuts down the logger
|
||||||
func (l *Logger) Stop(ctx context.Context) error {
|
func (l *Logger) Stop(ctx context.Context) error {
|
||||||
close(l.shutdown)
|
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
|
|
||||||
|
l.closeOnce.Do(func() {
|
||||||
|
close(l.shutdown)
|
||||||
|
})
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
l.wg.Wait()
|
l.wg.Wait()
|
||||||
close(done)
|
close(done)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user