3 / 3
Jun 2024

Randomly getting this error while accessing the data from mongoDB server version v7.0 and using golang mongo-driver v1.14.0.

Getting the below error while using mongoAggregation in code level:
connection(:1433[-1258]) incomplete read of full message: read tcp :63894-\u003e:1433: use of closed network connection

While looking into the mongod log getting the below error.

{"t":{"$date":"2024-05-31T10:15:07.561+00:00"},"s":"I", "c":"NETWORK", "id":51800, "ctx":"conn1744","msg":"client metadata","attr":{"remote":"10.1.0.44:54447","client":"conn1744","negotiatedCompressors":[],"doc":{"driver":{"name":"mongo-go-driver","version":"v1.15.0"},"os":{"type":"windows","architecture":"amd64"},"platform":"go1.19"}}} {"t":{"$date":"2024-05-31T10:15:08.664+00:00"},"s":"W", "c":"NETWORK", "id":4615610, "ctx":"conn1744","msg":"Failed to check socket connectivity","attr":{"error":{"code":6,"codeName":"HostUnreachable","errmsg":"peekASIOStream :: caused by :: Connection reset by peer"}}} {"t":{"$date":"2024-05-31T10:15:08.664+00:00"},"s":"I", "c":"-", "id":20883, "ctx":"conn1744","msg":"Interrupted operation as its client disconnected","attr":{"opId":32049}} {"t":{"$date":"2024-05-31T10:15:08.664+00:00"},"s":"I", "c":"EXECUTOR", "id":22989, "ctx":"conn1744","msg":"Error sending response to client. Ending connection from remote","attr":{"error":{"code":6,"codeName":"HostUnreachable","errmsg":"futurize :: caused by :: Connection reset by peer"},"remote":"10.1.0.44:54447","connectionId":1744}} {"t":{"$date":"2024-05-31T10:15:08.664+00:00"},"s":"I", "c":"NETWORK", "id":22944, "ctx":"conn1744","msg":"Connection ended","attr":{"remote":"10.1.0.44:54447","uuid":{"uuid":{"$uuid":"a7fadc10-10a2-4c79-803e-363368e38758"}},"connectionId":1744,"connectionCount":1636}}

Hi Arun

Given its random, it would indicate that some thresholds are being exceeded. Check your connection counts and limits, perhaps the connections are not being pooled properly?

Hope that helps

Craig.

func MongoConnector() (*mongo.Client, context.Context) { ctx := context.Background() mongoURI := "mongodb://userName:Password@DatabaseIP:Port/" if mongoURI != "" || len(mongoURI) != 0 { Client, err := mongo.Connect(ctx, options.Client().ApplyURI(mongoURI)) if err != nil { fmt.Println("Connection Issue to MongoDB....") return nil, nil } mongoClient = Client fmt.Println("Connected to MongoDB....") } else { fmt.Println("Mongo connection string is empty/please provide the valid connection parameter") return nil, nil } return mongoClient, ctx } // Close the connection string using the context func MongoDisconnect(MongoClient *mongo.Client, ctx context.Context) { err := MongoClient.Disconnect(ctx) if err != nil { fmt.Println("Error closing Mongo database connection for Context: %v with Exception: %v", ctx, err.Error()) } }

The above code I have used to make connection to mongoDB. After data retrieved, closed the same connection which was returned by MongoConnector() using mongo MongoDisconnect()

This issue occurs while continues DB hits within a fraction of seconds.

Tried below scenario’s,

  1. Used the connection string mentioned in the connector (mongodb://userName:Password@DatabaseIP:Port/)

  2. mongodb://userName:Password@DatabaseIP:Port/?&timeoutMS=120000&connectTimeoutMS=120000

  3. mongodb://userName:Password@DatabaseIP:Port/?maxPoolSize=100000&timeoutMS=120000&connectTimeoutMS=120000

Even after tried the above scenario the same issue is occuring.