From 4cbb6ce13bf93df2a9e251dfa87fbce9952ab8a6 Mon Sep 17 00:00:00 2001 From: Paul Nasrat Date: Sat, 26 Oct 2013 09:51:56 -0400 Subject: [PATCH 1/2] Introduce failing test case for #2089 --- container_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/container_test.go b/container_test.go index 50942c02d8..e863b9d84c 100644 --- a/container_test.go +++ b/container_test.go @@ -1652,3 +1652,29 @@ func TestMultipleVolumesFrom(t *testing.T) { t.Fail() } } + +func TestRestartGhost(t *testing.T) { + runtime := mkRuntime(t) + defer nuke(runtime) + + container, err := runtime.Create(&Config{ + Image: GetTestImage(runtime).ID, + Cmd: []string{"sh", "-c", "echo -n bar > /test/foo"}, + Volumes: map[string]struct{}{"/test": {}}, + }, + ) + + if err != nil { + t.Fatal(err) + } + if err := container.Kill(); err != nil { + t.Fatal(err) + } + + container.State.Ghost = true + _, err = container.Output() + + if err != nil { + t.Fatal(err) + } +} \ No newline at end of file From 95708dd35cd94a2c849e37efa05bb4e01ed36bb8 Mon Sep 17 00:00:00 2001 From: Paul Nasrat Date: Sun, 27 Oct 2013 09:04:57 -0400 Subject: [PATCH 2/2] Create new network on dead ghosts on restart. Fixes #2089 --- AUTHORS | 1 + container.go | 23 +++++++++++++++-------- container_test.go | 14 ++++++++------ 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/AUTHORS b/AUTHORS index 579ee0c48b..4ff695baf5 100644 --- a/AUTHORS +++ b/AUTHORS @@ -140,6 +140,7 @@ odk- Pascal Borreli Paul Bowsher Paul Hammond +Paul Nasrat Phil Spitler Piotr Bogdan pysqz diff --git a/container.go b/container.go index 2e52c95326..c330b86e33 100644 --- a/container.go +++ b/container.go @@ -1062,12 +1062,7 @@ func (container *Container) allocateNetwork() error { var iface *NetworkInterface var err error - if !container.State.Ghost { - iface, err = container.runtime.networkManager.Allocate() - if err != nil { - return err - } - } else { + if container.State.Ghost { manager := container.runtime.networkManager if manager.disabled { iface = &NetworkInterface{disabled: true} @@ -1077,8 +1072,20 @@ func (container *Container) allocateNetwork() error { Gateway: manager.bridgeNetwork.IP, manager: manager, } - ipNum := ipToInt(iface.IPNet.IP) - manager.ipAllocator.inUse[ipNum] = struct{}{} + if iface !=nil && iface.IPNet.IP != nil { + ipNum := ipToInt(iface.IPNet.IP) + manager.ipAllocator.inUse[ipNum] = struct{}{} + } else { + iface, err = container.runtime.networkManager.Allocate() + if err != nil { + return err + } + } + } + } else { + iface, err = container.runtime.networkManager.Allocate() + if err != nil { + return err } } diff --git a/container_test.go b/container_test.go index e863b9d84c..cbabffc364 100644 --- a/container_test.go +++ b/container_test.go @@ -1657,11 +1657,13 @@ func TestRestartGhost(t *testing.T) { runtime := mkRuntime(t) defer nuke(runtime) - container, err := runtime.Create(&Config{ - Image: GetTestImage(runtime).ID, - Cmd: []string{"sh", "-c", "echo -n bar > /test/foo"}, - Volumes: map[string]struct{}{"/test": {}}, - }, + container, _, err := runtime.Create( + &Config{ + Image: GetTestImage(runtime).ID, + Cmd: []string{"sh", "-c", "echo -n bar > /test/foo"}, + Volumes: map[string]struct{}{"/test": {}}, + }, + "", ) if err != nil { @@ -1677,4 +1679,4 @@ func TestRestartGhost(t *testing.T) { if err != nil { t.Fatal(err) } -} \ No newline at end of file +}