Преглед изворни кода

Merge pull request #7572 from shykes/workaround-api-shutdown

Workaround to avoid 5 second delay on graceful daemon restart
Victor Vieux пре 11 година
родитељ
комит
6b363b81de
1 измењених фајлова са 11 додато и 4 уклоњено
  1. 11 4
      engine/job.go

+ 11 - 4
engine/job.go

@@ -49,10 +49,17 @@ func (job *Job) Run() error {
 	if job.Eng.IsShutdown() {
 		return fmt.Errorf("engine is shutdown")
 	}
-	job.Eng.l.Lock()
-	job.Eng.tasks.Add(1)
-	job.Eng.l.Unlock()
-	defer job.Eng.tasks.Done()
+	// FIXME: this is a temporary workaround to avoid Engine.Shutdown
+	// waiting 5 seconds for server/api.ServeApi to complete (which it never will)
+	// everytime the daemon is cleanly restarted.
+	// The permanent fix is to implement Job.Stop and Job.OnStop so that
+	// ServeApi can cooperate and terminate cleanly.
+	if job.Name != "serveapi" {
+		job.Eng.l.Lock()
+		job.Eng.tasks.Add(1)
+		job.Eng.l.Unlock()
+		defer job.Eng.tasks.Done()
+	}
 	// FIXME: make this thread-safe
 	// FIXME: implement wait
 	if !job.end.IsZero() {