diff --git a/logging/monitor/monitor.go b/logging/monitor/monitor.go index a8e4e52324..e523a287f6 100644 --- a/logging/monitor/monitor.go +++ b/logging/monitor/monitor.go @@ -35,7 +35,7 @@ type monitor struct { droppedCount int // doneCh coordinates the shutdown of logCh - doneCh chan struct{} + doneCh chan bool // Defaults to 512. bufSize int @@ -58,7 +58,7 @@ func New(cfg Config) Monitor { sw := &monitor{ logger: cfg.Logger, logCh: make(chan []byte, bufSize), - doneCh: make(chan struct{}, 1), + doneCh: make(chan bool, 1), bufSize: bufSize, } @@ -72,7 +72,11 @@ func New(cfg Config) Monitor { // Stop deregisters the sink and stops the monitoring process func (d *monitor) Stop() int { d.logger.DeregisterSink(d.sink) - close(d.doneCh) + select { + case d.doneCh <- true: + default: + } + return d.droppedCount } diff --git a/logging/monitor/monitor_test.go b/logging/monitor/monitor_test.go index c12518f223..545f291af8 100644 --- a/logging/monitor/monitor_test.go +++ b/logging/monitor/monitor_test.go @@ -178,7 +178,7 @@ func TestMonitor_WriteStopped(t *testing.T) { mwriter := &monitor{ logger: logger, - doneCh: make(chan struct{}, 1), + doneCh: make(chan bool, 1), } mwriter.Stop()