diff --git a/container.go b/container.go index 8f993a35e1..b89885a17e 100644 --- a/container.go +++ b/container.go @@ -127,6 +127,7 @@ func (container *Container) FromDisk() error { if err := json.Unmarshal(data, container); err != nil { return err } + container.State.resetLock() return nil } diff --git a/runtime_test.go b/runtime_test.go index 28dcf6c279..5eeb0a155a 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -7,6 +7,7 @@ import ( "os/exec" "os/user" "testing" + "time" ) // FIXME: this is no longer needed @@ -302,11 +303,12 @@ func TestRestore(t *testing.T) { } // Simulate a crash/manual quit of dockerd: process dies, states stays 'Running' - if err := container2.Stop(); err != nil { - t.Fatalf("Could not stop container: %v", err) - } - + cStdin, _ := container2.StdinPipe() + cStdin.Close() + container2.State.setStopped(-1) + time.Sleep(time.Second) container2.State.Running = true + container2.ToDisk() if len(runtime1.List()) != 2 { t.Errorf("Expected 2 container, %v found", len(runtime1.List())) diff --git a/state.go b/state.go index f438ff8727..c7e89f2e65 100644 --- a/state.go +++ b/state.go @@ -39,6 +39,11 @@ func (s *State) setStopped(exitCode int) { s.broadcast() } +func (s *State) resetLock() { + s.stateChangeLock = &sync.Mutex{} + s.stateChangeCond = sync.NewCond(s.stateChangeLock) +} + func (s *State) broadcast() { s.stateChangeLock.Lock() s.stateChangeCond.Broadcast()