Skip to content

Commit b3186ef

Browse files
committed
Run imageservice.Cleanup() also before daemon start
Signed-off-by: Olli Janatuinen <olli.janatuinen@gmail.com>
1 parent daeb882 commit b3186ef

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

daemon/daemon.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,13 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S
10391039
TrustKey: trustKey,
10401040
})
10411041

1042+
// Image cleanup on some graph drivers (e.g. windowsfilter) takes so much time
1043+
// that it is not able to run during default 15 seconds shutdown timeout
1044+
// that why we run cleanup also just before daemon starts.
1045+
if !d.configStore.LiveRestoreEnabled {
1046+
d.imageService.Cleanup()
1047+
}
1048+
10421049
go d.execCommandGC()
10431050

10441051
d.containerd, err = libcontainerd.NewClient(ctx, d.containerdCli, filepath.Join(config.ExecRoot, "containerd"), config.ContainerdNamespace, d)

daemon/images/service.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"os"
66
"runtime"
7+
"time"
78

89
"github.com/docker/docker/container"
910
daemonevents "github.com/docker/docker/daemon/events"
@@ -157,16 +158,18 @@ func (i *ImageService) GetLayerMountID(cid string, os string) (string, error) {
157158
return i.layerStores[os].GetMountID(cid)
158159
}
159160

160-
// Cleanup resources before the process is shutdown.
161-
// called from daemon.go Daemon.Shutdown()
161+
// Cleanup resources before the process is started/shutdown.
162+
// called from daemon.go Daemon.NewDaemon() and Daemon.Shutdown()
162163
func (i *ImageService) Cleanup() {
164+
cleanupStart := time.Now()
163165
for os, ls := range i.layerStores {
164166
if ls != nil {
165167
if err := ls.Cleanup(); err != nil {
166168
logrus.Errorf("Error during layer Store.Cleanup(): %v %s", err, os)
167169
}
168170
}
169171
}
172+
logrus.Infof("ImageService cleanup took %.2f seconds", time.Since(cleanupStart).Seconds())
170173
}
171174

172175
// GraphDriverForOS returns the name of the graph drvier

integration/plugin/graphdriver/external_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ func testExternalGraphDriver(ext string, ec map[string]*graphEventsCounter) func
378378
assert.Check(t, ec[ext].gets >= 1)
379379
assert.Check(t, ec[ext].puts >= 1)
380380
assert.Check(t, is.Equal(ec[ext].stats, 5))
381-
assert.Check(t, is.Equal(ec[ext].cleanups, 2))
381+
assert.Check(t, is.Equal(ec[ext].cleanups, 4))
382382
assert.Check(t, ec[ext].applydiff >= 1)
383383
assert.Check(t, is.Equal(ec[ext].changes, 1))
384384
assert.Check(t, is.Equal(ec[ext].diffsize, 0))

0 commit comments

Comments
 (0)