Skip to content

Commit 04a0d6b

Browse files
committed
Change containerd monitor ticker to sleep
With the ticker this could end up just doing back-to-back checks, which isn't really what we want here. Instead use a sleep to ensure we actually sleep for the desired interval. Signed-off-by: Brian Goff <[email protected]>
1 parent f6a7763 commit 04a0d6b

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

image/store_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package image // import "github.com/docker/docker/image"
22

33
import (
4+
"fmt"
45
"runtime"
56
"testing"
67

@@ -171,6 +172,20 @@ func TestGetAndSetLastUpdated(t *testing.T) {
171172
assert.Equal(t, updated.IsZero(), false)
172173
}
173174

175+
func TestStoreLen(t *testing.T) {
176+
store, cleanup := defaultImageStore(t)
177+
defer cleanup()
178+
179+
expected := 10
180+
for i := 0; i < expected; i++ {
181+
_, err := store.Create([]byte(fmt.Sprintf(`{"comment": "abc%d", "rootfs": {"type": "layers"}}`, i)))
182+
assert.NoError(t, err)
183+
}
184+
numImages := store.Len()
185+
assert.Equal(t, expected, numImages)
186+
assert.Equal(t, len(store.Map()), numImages)
187+
}
188+
174189
type mockLayerGetReleaser struct{}
175190

176191
func (ls *mockLayerGetReleaser) Get(layer.ChainID) (layer.Layer, error) {

libcontainerd/remote_daemon.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,15 @@ func (r *remote) startContainerd() error {
263263
func (r *remote) monitorConnection(monitor *containerd.Client) {
264264
var transientFailureCount = 0
265265

266-
ticker := time.NewTicker(500 * time.Millisecond)
267-
defer ticker.Stop()
268-
269266
for {
270-
<-ticker.C
267+
select {
268+
case <-r.shutdownContext.Done():
269+
r.logger.Info("stopping healthcheck following graceful shutdown")
270+
monitor.Close()
271+
return
272+
case <-time.After(500 * time.Millisecond):
273+
}
274+
271275
ctx, cancel := context.WithTimeout(r.shutdownContext, healthCheckTimeout)
272276
_, err := monitor.IsServing(ctx)
273277
cancel()

0 commit comments

Comments
 (0)