Failed to get query provider: not connected to cluster

Hi, guys, i run couchbase in server with two servers after than I run this code

 
import (
    "fmt"
    "github.com/couchbase/gocb/v2"
    "log"
)
 
func main() {
    cluster, err := gocb.Connect(
        "127.0.0.1:8091",
        gocb.ClusterOptions{
            Username: "admin",
            Password: "adminadmin",
        },
    )
    if err != nil {
        log.Fatalf("Failed to connect to couchbase db: %v", err)
    }
 
    _, err = cluster.Bucket("testbucket").Ping(nil)
    if err != nil {
        log.Fatalf("Failed to ping: %v", err)
    }
 
    query := "select x.* from `testbucket` x limit 1;"
    rows, err := cluster.Query(query, nil)
    if err != nil {
        panic(err)
    }
 
    for rows.Next() {
        var u interface{}
        err := rows.Row(&u)
        if err != nil {
            panic(err)
        }
 
        fmt.Println(u)
    }
 
    err = rows.Err()
    if err != nil {
        panic(err)
    }
}

and always get failed to get query provider: not connected to cluster
anyone can help me and say what is the problem ?!

I user Enterprise Edition 6.5.1 build 6299 server and github.com/couchbase/gocb/v2 v2.1.0 SDK

Hi @RezaOptic! Look at Problem with bucketManager.CreateBucket
Connection is async so cluster.WaitUntilReady(2*time.Second, nil) before any operation on the cluster (e.g. a bucket selection) may help.

No, it’s not helping me.
I add cluster.Bucket(`testbucket`).WaitUntilReady(time.Minute, nil) I get this error operation has timed out
and as I see in hitter channel @MikeGoldsmith says

I believe cluster.WaitUntilReady is only expected to be called when performing cluster management operations, eg adding a bucket. You would not need to call this during normal init / application code unless you are altering the cluster configuation.

i do not want to create any bucket I just want to connect to exists bucket.

Hi @RezaOptic as @1110 suggests WaitUntilReady should work here as it will block until the underlying connections are established or the timeout is hit. If it’s failing to return successfully after a minute then it suggests that something is wrong. I’d recommend enabling logging (gocb.SetLogger(gocb.VerboseStdioLogger()) or gocb.SetLogger(gocb.DefaultStdioLogger())) to try to uncover what’s going on. As mentioned on Gitter I have also opened https://issues.couchbase.com/browse/GOCBC-879 to improve the handling around this - there’s also a bit more information on Problem with bucketManager.CreateBucket.

1 Like

I add the logger to my code and get these logs pastbin
at the end of logs, I see
GOCB 10:53:37.941153 memdclient.go:733: Authenticated successfully
and after that
GOCB 10:53:37.941378 memdclient.go:739: Failed to perform select bucket against server (authentication failure | {"status_code":36,"bucket":"newBucket","error_name":"EACCESS","error_description":"Not authorized for command",
I have auth problem or not because one time say Authenticated successfully and then say authentication failure :face_with_monocle:

@RezaOptic I understand your confusion. It looks like you have authenticated successfully against the cluster but failed to access the bucket. That would suggest that either the bucket doesn’t exist or the user you are using doesn’t have access to the bucket.

1 Like