瀏覽代碼

Improve graceful shutdown

Frédéric Guillot 8 年之前
父節點
當前提交
657e96e133
共有 1 個文件被更改,包括 3 次插入1 次删除
  1. 3 1
      daemon/daemon.go

+ 3 - 1
daemon/daemon.go

@@ -54,7 +54,9 @@ func Run(cfg *config.Config, store *storage.Storage) {
 
 
 	<-stop
 	<-stop
 	logger.Info("Shutting down the server...")
 	logger.Info("Shutting down the server...")
-	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
+	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
+	defer cancel()
+
 	server.Shutdown(ctx)
 	server.Shutdown(ctx)
 	store.Close()
 	store.Close()
 	logger.Info("Server gracefully stopped")
 	logger.Info("Server gracefully stopped")