mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #4534 from creack/fix_race_kill
Fix Race when killing the daemon
This commit is contained in:
commit
d8425d98e6
2 changed files with 32 additions and 14 deletions
|
@ -784,6 +784,7 @@ func (container *Container) monitor(callback execdriver.StartCallback) error {
|
||||||
utils.Errorf("Error running container: %s", err)
|
utils.Errorf("Error running container: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if container.runtime.srv.IsRunning() {
|
||||||
container.State.SetStopped(exitCode)
|
container.State.SetStopped(exitCode)
|
||||||
|
|
||||||
// FIXME: there is a race condition here which causes this to fail during the unit tests.
|
// FIXME: there is a race condition here which causes this to fail during the unit tests.
|
||||||
|
@ -796,6 +797,7 @@ func (container *Container) monitor(callback execdriver.StartCallback) error {
|
||||||
if err := container.ToDisk(); err != nil {
|
if err := container.ToDisk(); err != nil {
|
||||||
utils.Errorf("Error dumping container state to disk: %s\n", err)
|
utils.Errorf("Error dumping container state to disk: %s\n", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
container.cleanup()
|
container.cleanup()
|
||||||
|
|
24
server.go
24
server.go
|
@ -29,10 +29,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (srv *Server) Close() error {
|
|
||||||
return srv.runtime.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
// jobInitApi runs the remote api server `srv` as a daemon,
|
// jobInitApi runs the remote api server `srv` as a daemon,
|
||||||
// Only one api server can run at the same time - this is enforced by a pidfile.
|
// Only one api server can run at the same time - this is enforced by a pidfile.
|
||||||
// The signals SIGINT, SIGQUIT and SIGTERM are intercepted for cleanup.
|
// The signals SIGINT, SIGQUIT and SIGTERM are intercepted for cleanup.
|
||||||
|
@ -2330,6 +2326,7 @@ func NewServer(eng *engine.Engine, config *DaemonConfig) (*Server, error) {
|
||||||
pushingPool: make(map[string]chan struct{}),
|
pushingPool: make(map[string]chan struct{}),
|
||||||
events: make([]utils.JSONMessage, 0, 64), //only keeps the 64 last events
|
events: make([]utils.JSONMessage, 0, 64), //only keeps the 64 last events
|
||||||
listeners: make(map[string]chan utils.JSONMessage),
|
listeners: make(map[string]chan utils.JSONMessage),
|
||||||
|
running: true,
|
||||||
}
|
}
|
||||||
runtime.srv = srv
|
runtime.srv = srv
|
||||||
return srv, nil
|
return srv, nil
|
||||||
|
@ -2379,6 +2376,24 @@ func (srv *Server) GetEvents() []utils.JSONMessage {
|
||||||
return srv.events
|
return srv.events
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (srv *Server) SetRunning(status bool) {
|
||||||
|
srv.Lock()
|
||||||
|
defer srv.Unlock()
|
||||||
|
|
||||||
|
srv.running = status
|
||||||
|
}
|
||||||
|
|
||||||
|
func (srv *Server) IsRunning() bool {
|
||||||
|
srv.RLock()
|
||||||
|
defer srv.RUnlock()
|
||||||
|
return srv.running
|
||||||
|
}
|
||||||
|
|
||||||
|
func (srv *Server) Close() error {
|
||||||
|
srv.SetRunning(false)
|
||||||
|
return srv.runtime.Close()
|
||||||
|
}
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
runtime *Runtime
|
runtime *Runtime
|
||||||
|
@ -2387,4 +2402,5 @@ type Server struct {
|
||||||
events []utils.JSONMessage
|
events []utils.JSONMessage
|
||||||
listeners map[string]chan utils.JSONMessage
|
listeners map[string]chan utils.JSONMessage
|
||||||
Eng *engine.Engine
|
Eng *engine.Engine
|
||||||
|
running bool
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue