Skip to content

Commit fedff39

Browse files
committed
potential data race?
1 parent 49f3f0d commit fedff39

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

redis.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -448,16 +448,14 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
448448
// if not redis error, fail the connection
449449
return hitlessHandshakeErr
450450
}
451-
c.optLock.RLock()
452-
// handshake failed
451+
c.optLock.Lock()
452+
// handshake failed - check and modify config atomically
453453
switch c.opt.HitlessUpgradeConfig.Enabled {
454454
case hitless.MaintNotificationsEnabled:
455455
// enabled mode, fail the connection
456-
c.optLock.RUnlock()
456+
c.optLock.Unlock()
457457
return fmt.Errorf("failed to enable maintenance notifications: %w", hitlessHandshakeErr)
458458
default: // will handle auto and any other
459-
c.optLock.RUnlock()
460-
c.optLock.Lock()
461459
c.opt.HitlessUpgradeConfig.Enabled = hitless.MaintNotificationsDisabled
462460
c.optLock.Unlock()
463461
// auto mode, disable hitless upgrades and continue

0 commit comments

Comments
 (0)