Skip to content

Commit e6b0ac5

Browse files
ndyakovCopilot
authored andcommitted
Update redis.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent e47f040 commit e6b0ac5

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

redis.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,13 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
415415
// DialTimeout is shorter, cap the wait at DialTimeout
416416
var cancel context.CancelFunc
417417
waitCtx, cancel = context.WithTimeout(ctx, dialTimeout)
418-
defer cancel()
419418
}
420419
} else {
421420
// No command deadline, use DialTimeout to prevent waiting indefinitely
422421
var cancel context.CancelFunc
423422
waitCtx, cancel = context.WithTimeout(ctx, dialTimeout)
423+
}
424+
if cancel != nil {
424425
defer cancel()
425426
}
426427

0 commit comments

Comments
 (0)