From 04d803f7c91d4a40b90c695ebe10d702a6c03615 Mon Sep 17 00:00:00 2001 From: Marvin Zhang Date: Thu, 3 Apr 2025 12:14:20 +0800 Subject: [PATCH] fix: enhance MongoDB client connection error handling - Added a ping check after establishing a MongoDB client connection to ensure the connection is valid. - Implemented error logging for ping failures to improve debugging and provide clearer feedback on connection issues. - Ensured alignment with existing error handling practices in the codebase for consistency and maintainability. --- core/mongo/client.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/mongo/client.go b/core/mongo/client.go index 07fbc302..00bc7081 100644 --- a/core/mongo/client.go +++ b/core/mongo/client.go @@ -136,6 +136,11 @@ func newMongoClient(_opts *ClientOptions) (c *mongo.Client, err error) { if err != nil { return err } + err = c.Ping(ctx, nil) + if err != nil { + logger.Errorf("ping mongo error: %v", err) + return err + } logger.Infof("connected to mongo") return nil }