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:
parent
136631df46
commit
b06311a72e
3 changed files with 17 additions and 25 deletions
|
@ -1111,6 +1111,7 @@ func (container *Container) startLoggingToDisk() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *Container) waitForStart() error {
|
func (container *Container) waitForStart() error {
|
||||||
|
waitStart := make(chan struct{})
|
||||||
callback := func(command *execdriver.Command) {
|
callback := func(command *execdriver.Command) {
|
||||||
if command.Tty {
|
if command.Tty {
|
||||||
// The callback is called after the process Start()
|
// The callback is called after the process Start()
|
||||||
|
@ -1121,22 +1122,16 @@ func (container *Container) waitForStart() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
container.State.SetRunning(command.Pid())
|
container.State.SetRunning(command.Pid())
|
||||||
if err := container.ToDisk(); err != nil {
|
if err := container.toDisk(); err != nil {
|
||||||
utils.Debugf("%s", err)
|
utils.Debugf("%s", err)
|
||||||
}
|
}
|
||||||
|
close(waitStart)
|
||||||
}
|
}
|
||||||
|
|
||||||
// We use a callback here instead of a goroutine and an chan for
|
// We use a callback here instead of a goroutine and an chan for
|
||||||
// syncronization purposes
|
// syncronization purposes
|
||||||
cErr := utils.Go(func() error { return container.monitor(callback) })
|
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
|
// Start should not return until the process is actually running
|
||||||
select {
|
select {
|
||||||
case <-waitStart:
|
case <-waitStart:
|
||||||
|
|
|
@ -62,4 +62,5 @@ func initializer() {
|
||||||
|
|
||||||
func writeError(err error) {
|
func writeError(err error) {
|
||||||
fmt.Sprint(os.Stderr, err)
|
fmt.Sprint(os.Stderr, err)
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,6 @@ func (s *State) GetExitCode() int {
|
||||||
|
|
||||||
func (s *State) SetRunning(pid int) {
|
func (s *State) SetRunning(pid int) {
|
||||||
s.Lock()
|
s.Lock()
|
||||||
if !s.Running {
|
|
||||||
s.Running = true
|
s.Running = true
|
||||||
s.Paused = false
|
s.Paused = false
|
||||||
s.ExitCode = 0
|
s.ExitCode = 0
|
||||||
|
@ -122,20 +121,17 @@ func (s *State) SetRunning(pid int) {
|
||||||
s.StartedAt = time.Now().UTC()
|
s.StartedAt = time.Now().UTC()
|
||||||
close(s.waitChan) // fire waiters for start
|
close(s.waitChan) // fire waiters for start
|
||||||
s.waitChan = make(chan struct{})
|
s.waitChan = make(chan struct{})
|
||||||
}
|
|
||||||
s.Unlock()
|
s.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *State) SetStopped(exitCode int) {
|
func (s *State) SetStopped(exitCode int) {
|
||||||
s.Lock()
|
s.Lock()
|
||||||
if s.Running {
|
|
||||||
s.Running = false
|
s.Running = false
|
||||||
s.Pid = 0
|
s.Pid = 0
|
||||||
s.FinishedAt = time.Now().UTC()
|
s.FinishedAt = time.Now().UTC()
|
||||||
s.ExitCode = exitCode
|
s.ExitCode = exitCode
|
||||||
close(s.waitChan) // fire waiters for stop
|
close(s.waitChan) // fire waiters for stop
|
||||||
s.waitChan = make(chan struct{})
|
s.waitChan = make(chan struct{})
|
||||||
}
|
|
||||||
s.Unlock()
|
s.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue