Skip to content

Commit 49a2e43

Browse files
committed
deadlock?
1 parent e2d6be8 commit 49a2e43

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

hitless/hitless_manager.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,11 @@ func (hm *HitlessManager) Close() error {
215215

216216
// Shutdown the pool hook if it exists
217217
if hm.poolHooksRef != nil {
218-
err := hm.poolHooksRef.Shutdown(context.Background())
218+
// Use a timeout to prevent hanging indefinitely
219+
shutdownCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
220+
defer cancel()
221+
222+
err := hm.poolHooksRef.Shutdown(shutdownCtx)
219223
if err != nil {
220224
// was not able to close pool hook, keep closed state false
221225
hm.closed.Store(false)

hitless/pool_hook.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,25 @@ func (ph *PoolHook) processHandoffRequest(request HandoffRequest) {
397397
// Remove from pending map
398398
defer ph.pending.Delete(request.Conn.GetID())
399399

400-
// Perform the handoff
401-
err := ph.performConnectionHandoffWithPool(context.Background(), request.Conn, request.Pool)
400+
// Create a context that respects shutdown signal
401+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
402+
defer cancel()
403+
404+
// Create a context that also respects the shutdown signal
405+
shutdownCtx, shutdownCancel := context.WithCancel(ctx)
406+
defer shutdownCancel()
407+
408+
// Monitor shutdown signal in a separate goroutine
409+
go func() {
410+
select {
411+
case <-ph.shutdown:
412+
shutdownCancel()
413+
case <-shutdownCtx.Done():
414+
}
415+
}()
416+
417+
// Perform the handoff with cancellable context
418+
err := ph.performConnectionHandoffWithPool(shutdownCtx, request.Conn, request.Pool)
402419

403420
// If handoff failed, restore the handoff state for potential retry
404421
if err != nil {

redis.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,15 +460,16 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
460460
switch c.opt.HitlessUpgradeConfig.Enabled {
461461
case hitless.MaintNotificationsEnabled:
462462
// enabled mode, fail the connection
463+
c.optLock.RUnlock()
463464
return fmt.Errorf("failed to enable maintenance notifications: %w", hitlessHandshakeErr)
464465
case hitless.MaintNotificationsAuto:
466+
c.optLock.RUnlock()
467+
c.optLock.Lock()
465468
// auto mode, disable hitless upgrades and continue
466469
if err := c.disableHitlessUpgrades(); err != nil {
467470
// Log error but continue - auto mode should be resilient
468471
internal.Logger.Printf(ctx, "hitless: failed to disable hitless upgrades in auto mode: %v", err)
469472
}
470-
c.optLock.RUnlock()
471-
c.optLock.Lock()
472473
c.opt.HitlessUpgradeConfig.Enabled = hitless.MaintNotificationsDisabled
473474
c.optLock.Unlock()
474475
}
@@ -1263,5 +1264,3 @@ func (c *baseClient) pushNotificationHandlerContext(cn *pool.Conn) push.Notifica
12631264
Conn: &connectionAdapter{conn: cn}, // Wrap in adapter for easier interface access
12641265
}
12651266
}
1266-
1267-

0 commit comments

Comments
 (0)