mirror of
https://github.com/redis/go-redis.git
synced 2025-10-20 09:52:25 +03:00
fix credListeners map
This commit is contained in:
12
redis.go
12
redis.go
@@ -225,7 +225,7 @@ type baseClient struct {
|
|||||||
maintNotificationsManager *maintnotifications.Manager
|
maintNotificationsManager *maintnotifications.Manager
|
||||||
maintNotificationsManagerLock sync.RWMutex
|
maintNotificationsManagerLock sync.RWMutex
|
||||||
|
|
||||||
credListeners map[uint64]auth.CredentialsListener
|
credListeners map[*pool.Conn]auth.CredentialsListener
|
||||||
credListenersLock sync.RWMutex
|
credListenersLock sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,7 +305,7 @@ func (c *baseClient) _getConn(ctx context.Context) (*pool.Conn, error) {
|
|||||||
// The credentials listener is removed from the map when the connection is closed.
|
// The credentials listener is removed from the map when the connection is closed.
|
||||||
func (c *baseClient) connReAuthCredentialsListener(poolCn *pool.Conn) (auth.CredentialsListener, func()) {
|
func (c *baseClient) connReAuthCredentialsListener(poolCn *pool.Conn) (auth.CredentialsListener, func()) {
|
||||||
c.credListenersLock.RLock()
|
c.credListenersLock.RLock()
|
||||||
credListener, ok := c.credListeners[poolCn.GetID()]
|
credListener, ok := c.credListeners[poolCn]
|
||||||
c.credListenersLock.RUnlock()
|
c.credListenersLock.RUnlock()
|
||||||
if ok {
|
if ok {
|
||||||
return credListener.(auth.CredentialsListener), func() {
|
return credListener.(auth.CredentialsListener), func() {
|
||||||
@@ -319,7 +319,7 @@ func (c *baseClient) connReAuthCredentialsListener(poolCn *pool.Conn) (auth.Cred
|
|||||||
c.reAuthConnection(),
|
c.reAuthConnection(),
|
||||||
c.onAuthenticationErr(),
|
c.onAuthenticationErr(),
|
||||||
)
|
)
|
||||||
c.credListeners[poolCn.GetID()] = newCredListener
|
c.credListeners[poolCn] = newCredListener
|
||||||
return newCredListener, func() {
|
return newCredListener, func() {
|
||||||
c.removeCredListener(poolCn)
|
c.removeCredListener(poolCn)
|
||||||
}
|
}
|
||||||
@@ -328,7 +328,7 @@ func (c *baseClient) connReAuthCredentialsListener(poolCn *pool.Conn) (auth.Cred
|
|||||||
func (c *baseClient) removeCredListener(poolCn *pool.Conn) {
|
func (c *baseClient) removeCredListener(poolCn *pool.Conn) {
|
||||||
c.credListenersLock.Lock()
|
c.credListenersLock.Lock()
|
||||||
defer c.credListenersLock.Unlock()
|
defer c.credListenersLock.Unlock()
|
||||||
delete(c.credListeners, poolCn.GetID())
|
delete(c.credListeners, poolCn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *baseClient) reAuthConnection() func(poolCn *pool.Conn, credentials auth.Credentials) error {
|
func (c *baseClient) reAuthConnection() func(poolCn *pool.Conn, credentials auth.Credentials) error {
|
||||||
@@ -990,6 +990,10 @@ func NewClient(opt *Options) *Client {
|
|||||||
panic(fmt.Errorf("redis: failed to create pubsub pool: %w", err))
|
panic(fmt.Errorf("redis: failed to create pubsub pool: %w", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.opt.StreamingCredentialsProvider != nil {
|
||||||
|
c.credListeners = make(map[*pool.Conn]auth.CredentialsListener)
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize maintnotifications first if enabled and protocol is RESP3
|
// Initialize maintnotifications first if enabled and protocol is RESP3
|
||||||
if opt.MaintNotificationsConfig != nil && opt.MaintNotificationsConfig.Mode != maintnotifications.ModeDisabled && opt.Protocol == 3 {
|
if opt.MaintNotificationsConfig != nil && opt.MaintNotificationsConfig.Mode != maintnotifications.ModeDisabled && opt.Protocol == 3 {
|
||||||
err := c.enableMaintNotificationsUpgrades()
|
err := c.enableMaintNotificationsUpgrades()
|
||||||
|
Reference in New Issue
Block a user