Skip to content

Commit

Permalink
unlock before returning, no need for label
Browse files Browse the repository at this point in the history
comment, trigger build

return length written
  • Loading branch information
drewbailey committed Nov 5, 2019
1 parent 8ccb770 commit 03f0aff
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions command/agent/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,24 @@ func new(buf int, logger log.InterceptLogger, opts *log.LoggerOptions) *monitor
return sw
}

// Stop stops the monitoring process
// Stop deregisters the sink and stops the monitoring process
func (d *monitor) Stop() {
d.logger.DeregisterSink(d.sink)
close(d.doneCh)
}

// Start registers a sink on the monitor's logger and starts sending
// received log messages over the returned channel.
func (d *monitor) Start() <-chan []byte {
// register our sink with the logger
d.logger.RegisterSink(d.sink)

streamCh := make(chan []byte, d.bufSize)

// run a go routine that listens for streamed
// log messages and sends them to streamCh
go func() {
defer func() {
d.logger.DeregisterSink(d.sink)
close(streamCh)
}()
defer close(streamCh)

for {
select {
Expand All @@ -109,11 +108,10 @@ func (d *monitor) Start() <-chan []byte {
// to add a dropped message count warning
go func() {
// loop and check for dropped messages
LOOP:
for {
select {
case <-d.doneCh:
break LOOP
return
case <-time.After(d.droppedDuration):
d.Lock()

Expand All @@ -122,7 +120,8 @@ func (d *monitor) Start() <-chan []byte {
dropped := fmt.Sprintf("[WARN] Monitor dropped %d logs during monitor request\n", d.droppedCount)
select {
case <-d.doneCh:
break LOOP
d.Unlock()
return
// Try sending dropped message count to logCh in case
// there is room in the buffer now.
case d.logCh <- []byte(dropped):
Expand Down Expand Up @@ -168,5 +167,6 @@ func (d *monitor) Write(p []byte) (n int, err error) {
default:
d.droppedCount++
}
return

return len(p), nil
}

0 comments on commit 03f0aff

Please sign in to comment.