redis / go-redis

Redis Go client
https://redis.uptrace.dev
BSD 2-Clause "Simplified" License
20.22k stars 2.38k forks source link

Sentinel with PubSub deadlocks on Close #2943

Open danilobuerger opened 8 months ago

danilobuerger commented 8 months ago

When using the FailoverClient (Sentinel) with PubSub, calling Close will deadlock.

Expected Behavior

Close will close the PubSub and return.

Current Behavior

Close does not return.

Steps to Reproduce

func main() {
    client := redis.NewFailoverClient(&redis.FailoverOptions{
        MasterName:    "...",
        SentinelAddrs: []string{"..."},
    })

    pubSub := client.Subscribe(context.Background())
    pubSub.Channel()
    time.Sleep(1 * time.Second)
    log.Println("Subscribed")

    pubSub.Close()
    log.Println("Closed")
}

Version: 9.5.1

jerryyummy commented 2 days ago

this is my code

rc.client = redis.NewFailoverClient(&redis.FailoverOptions{ MasterName: "redis-master", SentinelAddrs: []string{"localhost:26379"}, })

pubSub := rc.client.Subscribe("")
pubSub.Channel()
time.Sleep(1 * time.Second)
log.Println("Subscribed")

pubSub.Close()
log.Println("Closed")

and the output is: redis: sentinel: new master="redis-master" addr="127.0.0.1:6379" Subscribed Closed

so i guess the reason is you do not configure your redis right or the version is not supported(my go-redis is v6)