New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't create source directory while the daemon is being shutdown, fix #30348 #33330

Merged
merged 1 commit into from Jun 7, 2017

Conversation

@coolljt0725
Contributor

coolljt0725 commented May 22, 2017

If a container mount the socket the daemon is listening on into
container while the daemon is being shutdown, the socket will
not exist on the host, then daemon will assume it's a directory
and create it on the host, this will cause the daemon can't start
next time.

fix issue #30348

To reproduce this issue, you can add following code

--- a/daemon/oci_linux.go
+++ b/daemon/oci_linux.go
@@ -8,6 +8,7 @@ import (
        "sort"
        "strconv"
        "strings"
+       "time"

        "github.com/Sirupsen/logrus"
        "github.com/docker/docker/container"
@@ -666,7 +667,8 @@ func (daemon *Daemon) createSpec(c *container.Container) (*libcontainerd.Spec, e
        if err := daemon.setupIpcDirs(c); err != nil {
                return nil, err
        }
-
+       fmt.Printf("===please stop the daemon===\n")
+       time.Sleep(time.Second * 2)
        ms, err := daemon.setupMounts(c)
        if err != nil {
                return nil, err

step1 run a container which has --restart always and -v /var/run/docker.sock:/sock

$ docker run -ti --restart always -v /var/run/docker.sock:/sock busybox
/ #

step2 exit the the container

/ # exit

and kill the daemon when you see

===please stop the daemon===

in the daemon log

The daemon can't restart again and fail with can't create unix socket /var/run/docker.sock: is a directory.

Signed-off-by: Lei Jitang leijitang@huawei.com

ping @cpuguy83 @thaJeztah

- What I did

- How I did it

- How to verify it

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah

This comment has been minimized.

Show comment
Hide comment
@thaJeztah

thaJeztah May 22, 2017

Member

@coolljt0725 looks like build is failing;

11:26:03 # github.com/docker/docker/daemon
11:26:03 daemon/volumes_windows.go:27: not enough arguments in call to mount.Setup
11:26:03 	have (string, number, number)
11:26:03 	want (string, int, int, func() error)
Member

thaJeztah commented May 22, 2017

@coolljt0725 looks like build is failing;

11:26:03 # github.com/docker/docker/daemon
11:26:03 daemon/volumes_windows.go:27: not enough arguments in call to mount.Setup
11:26:03 	have (string, number, number)
11:26:03 	want (string, int, int, func() error)
@coolljt0725

This comment has been minimized.

Show comment
Hide comment
@coolljt0725

coolljt0725 May 23, 2017

Contributor

@thaJeztah updated

Contributor

coolljt0725 commented May 23, 2017

@thaJeztah updated

@thaJeztah

This comment has been minimized.

Show comment
Hide comment
@thaJeztah
Member

thaJeztah commented May 30, 2017

@mlaventure

A few nits and a requested change to checkFun prototype.

Otherwise, LGTM. Thanks for finding this!

Show outdated Hide outdated daemon/volumes_unix.go
Show outdated Hide outdated daemon/volumes_unix.go
Show outdated Hide outdated volume/volume.go
Show outdated Hide outdated volume/volume.go
@coolljt0725

This comment has been minimized.

Show comment
Hide comment
@coolljt0725

coolljt0725 May 31, 2017

Contributor

@mlaventure update

Contributor

coolljt0725 commented May 31, 2017

@mlaventure update

Don't create source directory while the daemon is being shutdown, fix #…
…30348

If a container mount the socket the daemon is listening on into
container while the daemon is being shutdown, the socket will
not exist on the host, then daemon will assume it's a directory
and create it on the host, this will cause the daemon can't start
next time.

fix issue #30348

To reproduce this issue, you can add following code

```
--- a/daemon/oci_linux.go
+++ b/daemon/oci_linux.go
@@ -8,6 +8,7 @@ import (
        "sort"
        "strconv"
        "strings"
+       "time"

        "github.com/Sirupsen/logrus"
        "github.com/docker/docker/container"
@@ -666,7 +667,8 @@ func (daemon *Daemon) createSpec(c *container.Container) (*libcontainerd.Spec, e
        if err := daemon.setupIpcDirs(c); err != nil {
                return nil, err
        }
-
+       fmt.Printf("===please stop the daemon===\n")
+       time.Sleep(time.Second * 2)
        ms, err := daemon.setupMounts(c)
        if err != nil {
                return nil, err

```

step1 run a container which has `--restart always` and `-v /var/run/docker.sock:/sock`
```
$ docker run -ti --restart always -v /var/run/docker.sock:/sock busybox
/ #

```
step2 exit the the container
```
/ # exit
```
and kill the daemon when you see
```
===please stop the daemon===
```
in the daemon log

The daemon can't restart again and fail with `can't create unix socket /var/run/docker.sock: is a directory`.

Signed-off-by: Lei Jitang <leijitang@huawei.com>

@dhiltgen dhiltgen referenced this pull request May 31, 2017

Closed

17.06.0 RC2 tracker #2

23 of 23 tasks complete
@mlaventure

LGTM

Thanks!

@andrewhsu andrewhsu referenced this pull request Jun 6, 2017

Closed

17.06.0 RC3 tracker #8

40 of 40 tasks complete
// StoreHosts stores the addresses the daemon is listening on
func (daemon *Daemon) StoreHosts(hosts []string) {
if daemon.hosts == nil {
daemon.hosts = make(map[string]bool)

This comment has been minimized.

@AkihiroSuda

AkihiroSuda Jun 7, 2017

Member

Can we initialize daemon.hosts in NewDaemon()?

@AkihiroSuda

AkihiroSuda Jun 7, 2017

Member

Can we initialize daemon.hosts in NewDaemon()?

This comment has been minimized.

@coolljt0725

coolljt0725 Jun 7, 2017

Contributor

I have considered that, but it will have some duplicate code to dealing with the hosts config (https://github.com/moby/moby/blob/master/cmd/dockerd/daemon.go#L157).

@coolljt0725

coolljt0725 Jun 7, 2017

Contributor

I have considered that, but it will have some duplicate code to dealing with the hosts config (https://github.com/moby/moby/blob/master/cmd/dockerd/daemon.go#L157).

@AkihiroSuda

LGTM

@AkihiroSuda AkihiroSuda merged commit cd2255a into moby:master Jun 7, 2017

6 checks passed

dco-signed All commits are signed
experimental Jenkins build Docker-PRs-experimental 34571 has succeeded
Details
janky Jenkins build Docker-PRs 43169 has succeeded
Details
powerpc Jenkins build Docker-PRs-powerpc 3558 has succeeded
Details
windowsRS1 Jenkins build Docker-PRs-WoW-RS1 14449 has succeeded
Details
z Jenkins build Docker-PRs-s390x 3288 has succeeded
Details

@GordonTheTurtle GordonTheTurtle added this to the 17.06.0 milestone Jun 7, 2017

@coolljt0725 coolljt0725 deleted the coolljt0725:fix_sock_is_dir branch Jun 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment