`defer r.WaitTimeout(10s)` was in a wrong place and had caused the
daemon to hang for 10 seconds.
Fix #39025
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
| ... | ... |
@@ -164,7 +164,11 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
|
| 164 | 164 |
} |
| 165 | 165 |
|
| 166 | 166 |
ctx, cancel := context.WithCancel(context.Background()) |
| 167 |
- if err := cli.initContainerD(ctx); err != nil {
|
|
| 167 |
+ waitForContainerDShutdown, err := cli.initContainerD(ctx) |
|
| 168 |
+ if waitForContainerDShutdown != nil {
|
|
| 169 |
+ defer waitForContainerDShutdown(10 * time.Second) |
|
| 170 |
+ } |
|
| 171 |
+ if err != nil {
|
|
| 168 | 172 |
cancel() |
| 169 | 173 |
return err |
| 170 | 174 |
} |
| ... | ... |
@@ -145,30 +145,31 @@ func newCgroupParent(config *config.Config) string {
|
| 145 | 145 |
return cgroupParent |
| 146 | 146 |
} |
| 147 | 147 |
|
| 148 |
-func (cli *DaemonCli) initContainerD(ctx context.Context) error {
|
|
| 148 |
+func (cli *DaemonCli) initContainerD(ctx context.Context) (func(time.Duration) error, error) {
|
|
| 149 |
+ var waitForShutdown func(time.Duration) error |
|
| 149 | 150 |
if cli.Config.ContainerdAddr == "" {
|
| 150 | 151 |
systemContainerdAddr, ok, err := systemContainerdRunning(cli.Config.IsRootless()) |
| 151 | 152 |
if err != nil {
|
| 152 |
- return errors.Wrap(err, "could not determine whether the system containerd is running") |
|
| 153 |
+ return nil, errors.Wrap(err, "could not determine whether the system containerd is running") |
|
| 153 | 154 |
} |
| 154 | 155 |
if !ok {
|
| 155 | 156 |
opts, err := cli.getContainerdDaemonOpts() |
| 156 | 157 |
if err != nil {
|
| 157 |
- return errors.Wrap(err, "failed to generate containerd options") |
|
| 158 |
+ return nil, errors.Wrap(err, "failed to generate containerd options") |
|
| 158 | 159 |
} |
| 159 | 160 |
|
| 160 | 161 |
r, err := supervisor.Start(ctx, filepath.Join(cli.Config.Root, "containerd"), filepath.Join(cli.Config.ExecRoot, "containerd"), opts...) |
| 161 | 162 |
if err != nil {
|
| 162 |
- return errors.Wrap(err, "failed to start containerd") |
|
| 163 |
+ return nil, errors.Wrap(err, "failed to start containerd") |
|
| 163 | 164 |
} |
| 164 | 165 |
cli.Config.ContainerdAddr = r.Address() |
| 165 | 166 |
|
| 166 | 167 |
// Try to wait for containerd to shutdown |
| 167 |
- defer r.WaitTimeout(10 * time.Second) |
|
| 168 |
+ waitForShutdown = r.WaitTimeout |
|
| 168 | 169 |
} else {
|
| 169 | 170 |
cli.Config.ContainerdAddr = systemContainerdAddr |
| 170 | 171 |
} |
| 171 | 172 |
} |
| 172 | 173 |
|
| 173 |
- return nil |
|
| 174 |
+ return waitForShutdown, nil |
|
| 174 | 175 |
} |
| ... | ... |
@@ -5,6 +5,7 @@ import ( |
| 5 | 5 |
"fmt" |
| 6 | 6 |
"net" |
| 7 | 7 |
"os" |
| 8 |
+ "time" |
|
| 8 | 9 |
|
| 9 | 10 |
"github.com/docker/docker/daemon/config" |
| 10 | 11 |
"github.com/docker/docker/libcontainerd/supervisor" |
| ... | ... |
@@ -88,7 +89,7 @@ func newCgroupParent(config *config.Config) string {
|
| 88 | 88 |
return "" |
| 89 | 89 |
} |
| 90 | 90 |
|
| 91 |
-func (cli *DaemonCli) initContainerD(_ context.Context) error {
|
|
| 91 |
+func (cli *DaemonCli) initContainerD(_ context.Context) (func(time.Duration) error, error) {
|
|
| 92 | 92 |
system.InitContainerdRuntime(cli.Config.Experimental, cli.Config.ContainerdAddr) |
| 93 |
- return nil |
|
| 93 |
+ return nil, nil |
|
| 94 | 94 |
} |