Merge pull request #39026 from AkihiroSuda/fix-containerd-timeout
fix containerd WaitTimeout
This commit is contained in:
commit
965ab2ebbe
3 changed files with 15 additions and 9 deletions
|
@ -164,7 +164,11 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
|
|||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
if err := cli.initContainerD(ctx); err != nil {
|
||||
waitForContainerDShutdown, err := cli.initContainerD(ctx)
|
||||
if waitForContainerDShutdown != nil {
|
||||
defer waitForContainerDShutdown(10 * time.Second)
|
||||
}
|
||||
if err != nil {
|
||||
cancel()
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -145,30 +145,31 @@ func newCgroupParent(config *config.Config) string {
|
|||
return cgroupParent
|
||||
}
|
||||
|
||||
func (cli *DaemonCli) initContainerD(ctx context.Context) error {
|
||||
func (cli *DaemonCli) initContainerD(ctx context.Context) (func(time.Duration) error, error) {
|
||||
var waitForShutdown func(time.Duration) error
|
||||
if cli.Config.ContainerdAddr == "" {
|
||||
systemContainerdAddr, ok, err := systemContainerdRunning(cli.Config.IsRootless())
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not determine whether the system containerd is running")
|
||||
return nil, errors.Wrap(err, "could not determine whether the system containerd is running")
|
||||
}
|
||||
if !ok {
|
||||
opts, err := cli.getContainerdDaemonOpts()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to generate containerd options")
|
||||
return nil, errors.Wrap(err, "failed to generate containerd options")
|
||||
}
|
||||
|
||||
r, err := supervisor.Start(ctx, filepath.Join(cli.Config.Root, "containerd"), filepath.Join(cli.Config.ExecRoot, "containerd"), opts...)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to start containerd")
|
||||
return nil, errors.Wrap(err, "failed to start containerd")
|
||||
}
|
||||
cli.Config.ContainerdAddr = r.Address()
|
||||
|
||||
// Try to wait for containerd to shutdown
|
||||
defer r.WaitTimeout(10 * time.Second)
|
||||
waitForShutdown = r.WaitTimeout
|
||||
} else {
|
||||
cli.Config.ContainerdAddr = systemContainerdAddr
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
return waitForShutdown, nil
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/daemon/config"
|
||||
"github.com/docker/docker/libcontainerd/supervisor"
|
||||
|
@ -88,7 +89,7 @@ func newCgroupParent(config *config.Config) string {
|
|||
return ""
|
||||
}
|
||||
|
||||
func (cli *DaemonCli) initContainerD(_ context.Context) error {
|
||||
func (cli *DaemonCli) initContainerD(_ context.Context) (func(time.Duration) error, error) {
|
||||
system.InitContainerdRuntime(cli.Config.Experimental, cli.Config.ContainerdAddr)
|
||||
return nil
|
||||
return nil, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue