apache / apache/cassandra-gocql-driver
KeyspaceMetadata causes panic when describing aggregates
- Dominant language
- Go
- Stars
- 2.7k
- Forks
- 658
- PR merge metrics
- No merged PRs in 30d
Description
Please answer these questions before submitting your issue. Thanks!
### What version of Cassandra are you using?
Cassandra 3.11.11
### What version of Gocql are you using?
github.com/gocql/gocql@latest
### What version of Go are you using?
go version go1.15.14 windows/amd64
### What did you do?
```go
func getClusterAndSession(option Option) (*gocql.ClusterConfig, *gocql.Session, error) {
...
cluster := gocql.NewCluster(cass...)
cluster.Authenticator = gocql.PasswordAuthenticator{
Username: user,
Password: crypto.AesDecrypt(pass, crypto.EncryptKey),
}
cluster.NumConns = numConns
cluster.SocketKeepalive = time.Millisecond * 500
cluster.Keyspace = strings.ToLower(option.Keyspace)
cluster.Timeout = timeoutSecond * time.Second
cluster.ProtoVersion = protoVersion
cluster.PoolConfig.HostSelectionPolicy = gocql.TokenAwareHostPolicy(gocql.RoundRobinHostPolicy()) // This line causes panic
cluster.RetryPolicy = &gocql.SimpleRetryPolicy{NumRetries: retryNum}
cluster.DisableInitialHostLookup = option.DisableInitialHostLookup // If true, no token aware. Do not use in a production environment
// "ANY", "ONE", "TWO", "THREE", "QUORUM", "ALL", "LOCAL_QUORUM", "EACH_QUORUM", "LOCAL_ONE"
if consistency, err := env.GetVars("CONSISTENCY"); err == nil {
cluster.Consistency = gocql.ParseConsistency(strings.ToUpper(consistency[0]))
} else {
cluster.Consistency = gocql.LocalQuorum
}
if session, err := cluster.CreateSession(); err != nil {
return nil, nil, err
} else {
return cluster, session, nil
}
}
```
### What did you expect to see?
I hope it can create the connection normally
### What did you see instead?
```text
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xb4e466]
goroutine 1 [running]:
github.com/gocql/gocql.compileMetadata(0x4, 0xc000550660, 0xc000780000, 0x17e, 0x249, 0xc000bd2000, 0x1934, 0x1d99, 0xc00015b200, 0xe, ...)
D:/Develop/gocode/pkg/mod/github.com/gocql/gocql@v0.0.0-20211015133455-b225f9b53fa1/metadata.go:330 +0x2e6
github.com/gocql/gocql.(*schemaDescriber).refreshSchema(0xc00050a860, 0xe8c89b, 0x6, 0x6, 0x153e8e0)
D:/Develop/gocode/pkg/mod/github.com/gocql/gocql@v0.0.0-20211015133455-b225f9b53fa1/metadata.go:293 +0x40d
github.com/gocql/gocql.(*schemaDescriber).getSchema(0xc00050a860, 0xe8c89b, 0x6, 0x0, 0x0, 0x0)
D:/Develop/gocode/pkg/mod/github.com/gocql/gocql@v0.0.0-20211015133455-b225f9b53fa1/metadata.go:237 +0x109
github.com/gocql/gocql.(*Session).KeyspaceMetadata(0xc000218000, 0xe8c89b, 0x6, 0xc000291980, 0x0, 0x10)
D:/Develop/gocode/pkg/mod/github.com/gocql/gocql@v0.0.0-20211015133455-b225f9b53fa1/session.go:526 +0x91
github.com/gocql/gocql.(*tokenAwareHostPolicy).updateReplicas(0xc00055a100, 0xc000291980, 0xe8c89b, 0x6)
D:/Develop/gocode/pkg/mod/github.com/gocql/gocql@v0.0.0-20211015133455-b225f9b53fa1/policies.go:414 +0x9e
github.com/gocql/gocql.(*tokenAwareHostPolicy).KeyspaceChanged(0xc00055a100, 0xe8c89b, 0x6, 0x0, 0x0)
D:/Develop/gocode/pkg/mod/github.com/gocql/gocql@v0.0.0-20211015133455-b225f9b53fa1/policies.go:404 +0x99
github.com/gocql/gocql.(*Session).init(0xc000218000, 0xc000426000, 0x0)
D:/Develop/gocode/pkg/mod/github.com/gocql/gocql@v0.0.0-20211015133455-b225f9b53fa1/session.go:322 +0x775
github.com/gocql/gocql.NewSession(0xc0002903c0, 0x1, 0x1, 0xe8b00a, 0x5, 0x4, 0x2540be400, 0x23c34600, 0x2352, 0xe8c89b, ...)
D:/Develop/gocode/pkg/mod/github.com/gocql/gocql@v0.0.0-20211015133455-b225f9b53fa1/session.go:173 +0x8a9
github.com/gocql/gocql.(*ClusterConfig).CreateSession(...)
D:/Develop/gocode/pkg/mod/github.com/gocql/gocql@v0.0.0-20211015133455-b225f9b53fa1/cluster.go:205
git.wecise.com/wecise/common/cassandra.getClusterAndSession(0xe8c89b, 0x6, 0xc000209e00, 0xc000744000, 0x0, 0x0, 0xc000209d70)
D:/Develop/projects/wecise/common/cassandra/cassandra.go:137 +0x678
git.wecise.com/wecise/common/cassandra.GetClientByOption(0xe8c89b, 0x6, 0xc000744000, 0x3, 0x0, 0x0)
D:/Develop/projects/wecise/common/cassandra/cassandra.go:156 +0x45
git.wecise.com/wecise/common/multitenant.Init(0xf757c0, 0xc00000e018)
D:/Develop/projects/wecise/common/multitenant/multitenant.go:308 +0x207
main.main()
D:/Develop/projects/wecise/common/testrun.go:18 +0x9c
```
---
If you are having connectivity related issues please share the following additional information
### Describe your Cassandra cluster
please provide the following information
- output of `nodetool status`
```text
Datacenter: dc1
===============
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 172.26.38.247 11.25 GiB 16 100.0% c1883d65-9fe1-4fd2-90bf-f92839183a2d rack1
```
- output of `SELECT peer, rpc_address FROM system.peers`
```text
cassandra@cqlsh> SELECT peer, rpc_address FROM system.peers;
peer | rpc_address
------+-------------
(0 rows)
```
- rebuild your application with the `gocql_debug` tag and post the output
Contributor guide
Research direction
Start by reproducing the panic with Cassandra 3.11.11 and the token-aware host policy, then inspect compileMetadata in metadata.go:330 and the schemaDescriber path identified in the stack trace. Trace the KeyspaceMetadata call from policies.go and session.go; done means session creation completes without a nil-pointer panic when describing aggregates.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100