зеркало из https://github.com/microsoft/docker.git
Merge pull request #7301 from vieux/fix_goroutines_leak_exit_code
fix goroutines leak and exit code
This commit is contained in:
Коммит
64579f51fc
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче