forked from mirror/redis
Cleanup sentinel pubsub on close
Currently, the pubsub connection is aggressively disconnected when we close the upstream client which causes it to log something like: redis: 2018/11/09 09:10:07 pubsub.go:151: redis: discarding bad PubSub connection: read tcp 127.0.0.1:61025->127.0.0.1:26378: use of closed network connection This change simply cleans up the connection on close. We create new redis servers and connections for each set of independent tests and the logs were getting spammy.
This commit is contained in:
parent
58f22c56fd
commit
7fa8fdf3e7
10
sentinel.go
10
sentinel.go
|
@ -176,6 +176,7 @@ type sentinelFailover struct {
|
|||
masterName string
|
||||
_masterAddr string
|
||||
sentinel *SentinelClient
|
||||
pubsub *PubSub
|
||||
}
|
||||
|
||||
func (c *sentinelFailover) Close() error {
|
||||
|
@ -308,6 +309,9 @@ func (c *sentinelFailover) setSentinel(sentinel *SentinelClient) {
|
|||
}
|
||||
|
||||
func (c *sentinelFailover) closeSentinel() error {
|
||||
if err := c.pubsub.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
err := c.sentinel.Close()
|
||||
c.sentinel = nil
|
||||
return err
|
||||
|
@ -336,10 +340,8 @@ func (c *sentinelFailover) discoverSentinels(sentinel *SentinelClient) {
|
|||
}
|
||||
|
||||
func (c *sentinelFailover) listen(sentinel *SentinelClient) {
|
||||
pubsub := sentinel.Subscribe("+switch-master")
|
||||
defer pubsub.Close()
|
||||
|
||||
ch := pubsub.Channel()
|
||||
c.pubsub = sentinel.Subscribe("+switch-master")
|
||||
ch := c.pubsub.Channel()
|
||||
for {
|
||||
msg, ok := <-ch
|
||||
if !ok {
|
||||
|
|
Loading…
Reference in New Issue