Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

container: protect health monitor channel #35482

Merged
merged 1 commit into from Nov 14, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions container/health.go
@@ -1,6 +1,8 @@
package container

import (
"sync"

"github.com/docker/docker/api/types"
"github.com/sirupsen/logrus"
)
Expand All @@ -9,6 +11,7 @@ import (
type Health struct {
types.Health
stop chan struct{} // Write struct{} to stop the monitor
mu sync.Mutex
}

// String returns a human-readable description of the health-check state
Expand All @@ -26,9 +29,12 @@ func (s *Health) String() string {
}
}

// OpenMonitorChannel creates and returns a new monitor channel. If there already is one,
// it returns nil.
// OpenMonitorChannel creates and returns a new monitor channel. If there
// already is one, it returns nil.
func (s *Health) OpenMonitorChannel() chan struct{} {
s.mu.Lock()
defer s.mu.Unlock()

if s.stop == nil {
logrus.Debug("OpenMonitorChannel")
s.stop = make(chan struct{})
Expand All @@ -39,6 +45,9 @@ func (s *Health) OpenMonitorChannel() chan struct{} {

// CloseMonitorChannel closes any existing monitor channel.
func (s *Health) CloseMonitorChannel() {
s.mu.Lock()
defer s.mu.Unlock()

if s.stop != nil {
logrus.Debug("CloseMonitorChannel: waiting for probe to stop")
close(s.stop)
Expand Down