瀏覽代碼

lib/api: Shut the api down gracefully (fixes #7138) (#7157)

Simon Frei 5 年之前
父節點
當前提交
e1b958284e
共有 1 個文件被更改,包括 7 次插入1 次删除
  1. 7 1
      lib/api/api.go

+ 7 - 1
lib/api/api.go

@@ -415,7 +415,13 @@ func (s *service) Serve(ctx context.Context) error {
 		// Restart due to listen/serve failure
 		// Restart due to listen/serve failure
 		l.Warnln("GUI/API:", err, "(restarting)")
 		l.Warnln("GUI/API:", err, "(restarting)")
 	}
 	}
-	srv.Close()
+	// Give it a moment to shut down gracefully, e.g. if we are restarting
+	// due to a config change through the API, let that finish successfully.
+	timeout, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
+	defer cancel()
+	if err := srv.Shutdown(timeout); err == timeout.Err() {
+		srv.Close()
+	}
 
 
 	return err
 	return err
 }
 }