From 4e4564c9cc3c671392565419ab90aaf7e8d0f924 Mon Sep 17 00:00:00 2001 From: "Xinwei Xiong (cubxxw)" <3293172751nss@gmail.com> Date: Fri, 12 Jan 2024 17:45:50 +0800 Subject: [PATCH] fix: fix scripts functions upload Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com> --- tools/component/component.go | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/tools/component/component.go b/tools/component/component.go index 3e4705a4c..9ccf7c209 100644 --- a/tools/component/component.go +++ b/tools/component/component.go @@ -141,35 +141,24 @@ func getEnv(key, fallback string) string { return fallback } -// checkMongo checks the MongoDB connection with retries and timeout +// checkMongo checks the MongoDB connection without retries func checkMongo() (string, error) { uri := getEnv("MONGO_URI", buildMongoURI()) - var client *mongo.Client - var err error - for attempt := 0; attempt <= maxRetry; attempt++ { - ctx, cancel := context.WithTimeout(context.Background(), mongoConnTimeout) - defer cancel() + ctx, cancel := context.WithTimeout(context.Background(), mongoConnTimeout) + defer cancel() - client, err = mongo.Connect(ctx, options.Client().ApplyURI(uri)) - if err == nil { - break - } - if attempt < maxRetry { - fmt.Printf("Failed to connect to MongoDB, retrying: %s\n", err) - time.Sleep(time.Second * time.Duration(attempt+1)) // Exponential backoff - } - } + client, err := mongo.Connect(ctx, options.Client().ApplyURI(uri)) if err != nil { - return "", err // Wrap or handle the error as needed + return "", err // Handle the error as needed } defer client.Disconnect(context.Background()) - ctx, cancel := context.WithTimeout(context.Background(), mongoConnTimeout) + ctx, cancel = context.WithTimeout(context.Background(), mongoConnTimeout) defer cancel() if err = client.Ping(ctx, nil); err != nil { - return "", err // Wrap or handle the error as needed + return "", err // Handle the error as needed } str := "The addr is: " + strings.Join(config.Config.Mongo.Address, ",")