Go SDK on Linux seems to leak connections

Hello,

I am writing a simple application to read/write data to Couchbase using gopkg.in/couchbase/gocb.v1

Problem: When application is built for Linux, its constantly opening new connections to CB ( 10-20 per second ) until it eventually crashes. The Get/Upsert operations succeed, but the number of threads is constantly increasing. This behavior does not happen when running on Mac, only Linux

Go Version : go1.15.2

When I build/run locally on my a mac, it only opens 10 connections and I see this in the logs

GOCB 21:19:03.265121 agentrouting.go:138: Authenticating…
GOCB 21:19:03.275375 agent.go:797: Attempting to request CCCP configuration
GOCB 21:19:03.281946 agent.go:826: Using network type default for connections
GOCB 21:19:03.281972 agent.go:833: Successfully connected
GOCB 15:57:14.420686 agentcccpcfg.go:76: CCCPPOLL: Received new config
GOCB 15:57:14.420732 agentrouting.go:232: Ignoring configuration with identical revision number

When built/run on Linux, the number of connections grows at a rate of 10-20 per second, and it keeps switching routing data:

GOCB 21:19:03.265121 agentrouting.go:138: Authenticating…
GOCB 21:19:03.275375 agent.go:797: Attempting to request CCCP configuration
GOCB 21:19:03.281946 agent.go:826: Using network type default for connections
GOCB 21:19:03.281972 agent.go:833: Successfully connected
GOCB 15:57:14.420686 agentcccpcfg.go:76: CCCPPOLL: Received new config
GOCB 21:07:01.033814 agentrouting.go:245: Switching routing data (update)…
GOCB 21:07:01.033974 agentrouting.go:246: New Routing Data:

Sample Code:

    var cbBucket *gocb.Bucket
    var bucketName = "testBucket"

    cx := "couchbase://" + cbHost

    cluster, err := gocb.Connect(cx)
    cluster.Authenticate(gocb.PasswordAuthenticator{
            Username: cbUser,
            Password: viper.GetString("CB_PASS"),
    })

    if err != nil {
            log.Println("Error connecting to Couchbase:", err)
            panic(err)
    }

    bucket, err := cluster.OpenBucket(bucketName, "")
    cbBucket = bucket

    if err != nil {
            log.Println("Error connecting to Bucket:", err)
            panic(err)
    }

    var Data DataStruct
    cas, err := cbBucket.Get(document, &Data)

Just looking for ways to debug this behavior. Seems to be something related to

Hi @chvck can you please help @marzlarz thanks

1 Like

Hi @marzlarz even when switching configuration data the number of connections shouldn’t be growing. On receipt of a new config with a newer revId than the one we have we will shut down any connections to nodes no longer in the config, create new connections for any new nodes in the config, and just keep the connections active for nodes that exist across both.

Do you have any logs that you could share so that I can take a look at what’s going on?

@chvck @AV25242 Thank you both for responding so quickly.

After sleeping on it, I realized that my local changes (mac) werent pushed to the linux server I was building on. The fix between the two was to move the Couchbase connection and opening of the bucket globally rather than inside my function.

This explains why the number of connections continued to grow, and why I kept seeing the same RevID for the config.

Thanks again, you can mark this as resolved.

Thanks @marzlarz and glad you were able to find a solution.