mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #33781 from mlaventure/fix-healhcheck-goroutine-leak
Prevent a goroutine leak when healthcheck gets stopped
This commit is contained in:
commit
da28210a15
1 changed files with 4 additions and 2 deletions
|
@ -193,7 +193,7 @@ func monitor(d *Daemon, c *container.Container, stop chan struct{}, probe probe)
|
||||||
logrus.Debugf("Running health check for container %s ...", c.ID)
|
logrus.Debugf("Running health check for container %s ...", c.ID)
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
ctx, cancelProbe := context.WithTimeout(context.Background(), probeTimeout)
|
ctx, cancelProbe := context.WithTimeout(context.Background(), probeTimeout)
|
||||||
results := make(chan *types.HealthcheckResult)
|
results := make(chan *types.HealthcheckResult, 1)
|
||||||
go func() {
|
go func() {
|
||||||
healthChecksCounter.Inc()
|
healthChecksCounter.Inc()
|
||||||
result, err := probe.run(ctx, d, c)
|
result, err := probe.run(ctx, d, c)
|
||||||
|
@ -216,8 +216,10 @@ func monitor(d *Daemon, c *container.Container, stop chan struct{}, probe probe)
|
||||||
select {
|
select {
|
||||||
case <-stop:
|
case <-stop:
|
||||||
logrus.Debugf("Stop healthcheck monitoring for container %s (received while probing)", c.ID)
|
logrus.Debugf("Stop healthcheck monitoring for container %s (received while probing)", c.ID)
|
||||||
// Stop timeout and kill probe, but don't wait for probe to exit.
|
|
||||||
cancelProbe()
|
cancelProbe()
|
||||||
|
// Wait for probe to exit (it might take a while to respond to the TERM
|
||||||
|
// signal and we don't want dying probes to pile up).
|
||||||
|
<-results
|
||||||
return
|
return
|
||||||
case result := <-results:
|
case result := <-results:
|
||||||
handleProbeResult(d, c, result, stop)
|
handleProbeResult(d, c, result, stop)
|
||||||
|
|
Loading…
Reference in a new issue