1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

fix goroutines leak and exit code

Docker-DCO-1.1-Signed-off-by: Victor Vieux <vieux@docker.com> (github: vieux)

Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
Victor Vieux 2014-07-29 07:14:10 +00:00
parent 136631df46
commit b06311a72e
3 changed files with 17 additions and 25 deletions

View file

@ -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:

View file

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

View file

@ -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()
}