From f30d1c1835618eadea5d0a68d1301dffd9f09b22 Mon Sep 17 00:00:00 2001 From: Aidan Hobson Sayers Date: Mon, 27 Apr 2015 01:07:30 +0100 Subject: [PATCH] Prevent deadlock on attempt to use own net Signed-off-by: Aidan Hobson Sayers --- daemon/container.go | 3 +++ integration-cli/docker_cli_run_test.go | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/daemon/container.go b/daemon/container.go index bdfcbf4477..01eef4d31d 100644 --- a/daemon/container.go +++ b/daemon/container.go @@ -1515,6 +1515,9 @@ func (container *Container) getNetworkedContainer() (*Container, error) { if err != nil { return nil, err } + if container == nc { + return nil, fmt.Errorf("cannot join own network") + } if !nc.IsRunning() { return nil, fmt.Errorf("cannot join network of a non running container: %s", parts[1]) } diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index 342137c477..b7961126cc 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -2657,6 +2657,14 @@ func (s *DockerSuite) TestContainerNetworkMode(c *check.C) { } } +func (s *DockerSuite) TestContainerNetworkModeToSelf(c *check.C) { + cmd := exec.Command(dockerBinary, "run", "--name=me", "--net=container:me", "busybox", "true") + out, _, err := runCommandWithOutput(cmd) + if err == nil || !strings.Contains(out, "cannot join own network") { + c.Fatalf("using container net mode to self should result in an error") + } +} + func (s *DockerSuite) TestRunModePidHost(c *check.C) { testRequires(c, NativeExecDriver, SameHostDaemon)