Merge pull request #7301 from vieux/fix_goroutines_leak_exit_code

fix goroutines leak and exit code
This commit is contained in:
Michael Crosby 2014-08-12 17:37:24 -07:00
Родитель 136631df46 b06311a72e
Коммит 64579f51fc
3 изменённых файлов: 17 добавлений и 25 удалений

Просмотреть файл

@ -1111,6 +1111,7 @@ func (container *Container) startLoggingToDisk() error {
}
func (container *Container) waitForStart() error {
waitStart := make(chan struct{})
callback := func(command *execdriver.Command) {
if command.Tty {
// The callback is called after the process Start()
@ -1121,22 +1122,16 @@ func (container *Container) waitForStart() error {
}
}
container.State.SetRunning(command.Pid())
if err := container.ToDisk(); err != nil {
if err := container.toDisk(); err != nil {
utils.Debugf("%s", err)
}
close(waitStart)
}
// We use a callback here instead of a goroutine and an chan for
// syncronization purposes
cErr := utils.Go(func() error { return container.monitor(callback) })
waitStart := make(chan struct{})
go func() {
container.State.WaitRunning(-1 * time.Second)
close(waitStart)
}()
// Start should not return until the process is actually running
select {
case <-waitStart:

Просмотреть файл

@ -62,4 +62,5 @@ func initializer() {
func writeError(err error) {
fmt.Sprint(os.Stderr, err)
os.Exit(1)
}

Просмотреть файл

@ -114,28 +114,24 @@ func (s *State) GetExitCode() int {
func (s *State) SetRunning(pid int) {
s.Lock()
if !s.Running {
s.Running = true
s.Paused = false
s.ExitCode = 0
s.Pid = pid
s.StartedAt = time.Now().UTC()
close(s.waitChan) // fire waiters for start
s.waitChan = make(chan struct{})
}
s.Running = true
s.Paused = false
s.ExitCode = 0
s.Pid = pid
s.StartedAt = time.Now().UTC()
close(s.waitChan) // fire waiters for start
s.waitChan = make(chan struct{})
s.Unlock()
}
func (s *State) SetStopped(exitCode int) {
s.Lock()
if s.Running {
s.Running = false
s.Pid = 0
s.FinishedAt = time.Now().UTC()
s.ExitCode = exitCode
close(s.waitChan) // fire waiters for stop
s.waitChan = make(chan struct{})
}
s.Running = false
s.Pid = 0
s.FinishedAt = time.Now().UTC()
s.ExitCode = exitCode
close(s.waitChan) // fire waiters for stop
s.waitChan = make(chan struct{})
s.Unlock()
}