-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
go-redis/v8 nil shard in the shards map #2126
Comments
|
We use a structure import "github.com/go-redis/redis/v8"
...
type S struct {
mu sync.RWMutex
ring *redis.Ring
...
}
`*redis.Ring` is the one from `package redis` in go-redis/redis@v8.11.4. And function func (s *S) f() {
s.mu.Lock()
defer s.mu.Unlock()
...
// here we change opts.Addrs map
var newOpts redis.RingOptions = ...
// here the shards map gets changed and we substitute the old ring with the new one
prev, s.ring = s.ring, redis.NewRing(&newOpts) the//new one
...
defer func() {
if prev != nil {
go func() {
if err := prev.Close(); err != nil {
log(err)
}
}()
}
}()
} At some random points of time we call However, as I can see in the source code, between the moment when the hash is calculated and the moment when we retrieve a shard by it a bit later, there is no lock held. I suppose that we might have a situation, when things happen in the following order:
|
Expected Behavior
no panic due to nil pointer dereference after retrieving a nil shard from the shards map
Current Behavior
There is no check if a shard is not nil before returning it.
It might cause panic due to nil pointer dereference here
Possible Solution
Check if shard is not nil before returning it.
Steps to Reproduce
We have a proprietary code which wraps
go-redis/go
and sometimes recreates the Ring structure (and hence repopulating the shards map), all while holding the mutex.Despite it, sometimes after the ring is recreated, we get panic in the place linked above because the shard retrieved by the name is nil.
Possible Implementation
The text was updated successfully, but these errors were encountered: