From 95db792c93656b07745137c020caa0122a3949c0 Mon Sep 17 00:00:00 2001 From: Vlad Vitan <23100181+vlasebian@users.noreply.github.com> Date: Thu, 19 Feb 2026 15:04:26 +0200 Subject: [PATCH] all: Use separate ctx for Redis mutex unlock --- pkg/redis/redis.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/redis/redis.go b/pkg/redis/redis.go index 2f1f7f08cb..282d10c15b 100644 --- a/pkg/redis/redis.go +++ b/pkg/redis/redis.go @@ -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") } }()