Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit 4437f48

Browse files
authored
Merge pull request #306 from andrewhsu/health
[17.11] container: protect health monitor channel
2 parents f271e4e + 74f7c76 commit 4437f48

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

components/engine/container/health.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package container
22

33
import (
4+
"sync"
5+
46
"github.com/docker/docker/api/types"
57
"github.com/sirupsen/logrus"
68
)
@@ -9,6 +11,7 @@ import (
911
type Health struct {
1012
types.Health
1113
stop chan struct{} // Write struct{} to stop the monitor
14+
mu sync.Mutex
1215
}
1316

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

29-
// OpenMonitorChannel creates and returns a new monitor channel. If there already is one,
30-
// it returns nil.
32+
// OpenMonitorChannel creates and returns a new monitor channel. If there
33+
// already is one, it returns nil.
3134
func (s *Health) OpenMonitorChannel() chan struct{} {
35+
s.mu.Lock()
36+
defer s.mu.Unlock()
37+
3238
if s.stop == nil {
3339
logrus.Debug("OpenMonitorChannel")
3440
s.stop = make(chan struct{})
@@ -39,6 +45,9 @@ func (s *Health) OpenMonitorChannel() chan struct{} {
3945

4046
// CloseMonitorChannel closes any existing monitor channel.
4147
func (s *Health) CloseMonitorChannel() {
48+
s.mu.Lock()
49+
defer s.mu.Unlock()
50+
4251
if s.stop != nil {
4352
logrus.Debug("CloseMonitorChannel: waiting for probe to stop")
4453
close(s.stop)

0 commit comments

Comments
 (0)