Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions pkg/server/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package server

import (
"sync"
"time"

eventtypes "github.com/containerd/containerd/api/events"
Expand Down Expand Up @@ -56,7 +57,9 @@ type eventMonitor struct {
}

type backOff struct {
queuePool map[string]*backOffQueue
queuePool map[string]*backOffQueue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go fmt

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is gofmt result.

// tickerMu is mutex used to protect the ticker.
tickerMu sync.Mutex
ticker *time.Ticker
minDuration time.Duration
maxDuration time.Duration
Expand Down Expand Up @@ -120,8 +123,8 @@ func (em *eventMonitor) start() (<-chan struct{}, error) {
return nil, errors.New("event channel is nil")
}
closeCh := make(chan struct{})
backOffCheckCh := em.backOff.start()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good!

go func() {
backOffCheckCh := em.backOff.start()
for {
select {
case e := <-em.ch:
Expand Down Expand Up @@ -366,12 +369,18 @@ func (b *backOff) reBackOff(key string, events []interface{}, oldDuration time.D
}

func (b *backOff) start() <-chan time.Time {
b.tickerMu.Lock()
defer b.tickerMu.Unlock()
b.ticker = time.NewTicker(b.checkDuration)
return b.ticker.C
}

func (b *backOff) stop() {
b.ticker.Stop()
b.tickerMu.Lock()
defer b.tickerMu.Unlock()
if b.ticker != nil {
b.ticker.Stop()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else...logrus.WithError(err).Error("attempt to stop ticker before start has completed allocating the ticker")

note: should be impossible for this to happen now that you have a mutex... if the log is impossible we don't need the nil check..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is possible, user may CTRL+C before CRI service starts.

Copy link
Member

@mikebrow mikebrow Mar 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user interrupts ... interesting thx

}

func newBackOffQueue(events []interface{}, init time.Duration, c clock.Clock) *backOffQueue {
Expand Down