Skip to content

Commit 2890d51

Browse files
ndyakovCopilot
andauthored
Update redis.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 038cf1f commit 2890d51

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,11 +415,12 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
415415
} else {
416416
// DialTimeout is shorter, cap the wait at DialTimeout
417417
waitCtx, cancel = context.WithTimeout(ctx, dialTimeout)
418-
defer cancel()
419418
}
420419
} else {
421420
// No command deadline, use DialTimeout to prevent waiting indefinitely
422421
waitCtx, cancel = context.WithTimeout(ctx, dialTimeout)
422+
}
423+
if cancel != nil {
423424
defer cancel()
424425
}
425426

0 commit comments

Comments
 (0)