Merge pull request #35482 from stevvooe/protect-health-monitor-channel

container: protect health monitor channel
This commit is contained in:
Yong Tang 2017-11-14 11:25:14 -08:00 committed by GitHub
commit e4d0fe84f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,8 @@
package container
import (
"sync"
"github.com/docker/docker/api/types"
"github.com/sirupsen/logrus"
)
@ -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
@ -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{})
@ -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)