0

I have created a AWS documentdb instance of t4g.medium size. I am trying to insert data in a collection. While monitoring the connection count in AWS monitor console, I observed that for every request 3 connections are getting created. Had any body faced similar issue or any idea why 3 connections are getting created for each request.

Connection code snippet in Go:

func createConnection() (*mongo.Client, error) {
    clusterEndpoint := fmt.Sprintf("%v:%v", host, port)
    connectionURI := fmt.Sprintf(ConnectionStringTemplate, username, password, clusterEndpoint, database, ReadPreference)
    tlsConfig, err := getCustomTLSConfig(CaFilePath)
    if err != nil {
        log.Errorf(context.Background(), "Failed getting TLS configuration: %v", err)
    }
    clientOptions := options.Client().ApplyURI(connectionURI).SetTLSConfig(tlsConfig)
    clientOptions = clientOptions.SetMaxPoolSize(1)
    clientOptions = clientOptions.SetMinPoolSize(1)

    ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
    defer cancel()

    client, err := mongo.Connect(ctx, clientOptions)
    if err != nil {
        return nil, err
    }

    // Test the connection
    err = client.Ping(ctx, nil)
    if err != nil {
        return nil, err
    }
    log.Infof(context.Background(), "Connection created successfully")

    return client, nil
}

AWS Monitor screenshot

I have tried setting max and min pool size to 1, but it didn't help either.

0 Answers0