@@ -107,10 +107,17 @@ func (p *cmdProbe) run(ctx context.Context, d *Daemon, container *container.Cont
107
107
}
108
108
109
109
// Update the container's Status.Health struct based on the latest probe's result.
110
- func handleProbeResult (d * Daemon , c * container.Container , result * types.HealthcheckResult ) {
110
+ func handleProbeResult (d * Daemon , c * container.Container , result * types.HealthcheckResult , done chan struct {} ) {
111
111
c .Lock ()
112
112
defer c .Unlock ()
113
113
114
+ // probe may have been cancelled while waiting on lock. Ignore result then
115
+ select {
116
+ case <- done :
117
+ return
118
+ default :
119
+ }
120
+
114
121
retries := c .Config .Healthcheck .Retries
115
122
if retries <= 0 {
116
123
retries = defaultProbeRetries
@@ -183,7 +190,7 @@ func monitor(d *Daemon, c *container.Container, stop chan struct{}, probe probe)
183
190
cancelProbe ()
184
191
return
185
192
case result := <- results :
186
- handleProbeResult (d , c , result )
193
+ handleProbeResult (d , c , result , stop )
187
194
// Stop timeout
188
195
cancelProbe ()
189
196
case <- ctx .Done ():
@@ -193,7 +200,7 @@ func monitor(d *Daemon, c *container.Container, stop chan struct{}, probe probe)
193
200
Output : fmt .Sprintf ("Health check exceeded timeout (%v)" , probeTimeout ),
194
201
Start : startTime ,
195
202
End : time .Now (),
196
- })
203
+ }, stop )
197
204
cancelProbe ()
198
205
// Wait for probe to exit (it might take a while to respond to the TERM
199
206
// signal and we don't want dying probes to pile up).
0 commit comments