Prechádzať zdrojové kódy

Merge pull request #7301 from vieux/fix_goroutines_leak_exit_code

fix goroutines leak and exit code
Michael Crosby 11 rokov pred
rodič
commit
64579f51fc
3 zmenil súbory, kde vykonal 17 pridanie a 25 odobranie
  1. 3 8
      daemon/container.go
  2. 1 0
      daemon/execdriver/native/init.go
  3. 13 17
      daemon/state.go

+ 3 - 8
daemon/container.go

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

+ 1 - 0
daemon/execdriver/native/init.go

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

+ 13 - 17
daemon/state.go

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