Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,11 @@ func LockedWatch(ctx context.Context, r WatchCmdable, k, id string, expiration t
return err
}
defer func() {
if err := UnlockMutex(ctx, r, k, id, expiration); err != nil {
// Use a separate context with timeout for unlocking to ensure that we attempt to unlock the mutex even if
// the main context is already expired.
unlockCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 5*time.Second)
defer cancel()
if err := UnlockMutex(unlockCtx, r, k, id, expiration); err != nil {
log.FromContext(ctx).WithField("key", k).WithError(err).Error("Failed to unlock mutex")
}
}()
Expand Down
Loading