Tencent/WeKnora · error
redis lock ownership lost
Error message
redis lock ownership lost
What it means
Sentinel ErrLockOwnershipLost in redislock: exclusive ownership of the token-owned Redis lock can no longer be guaranteed — either the final release found the token no longer owned the key, or a renewal attempt failed mid-critical-section. The owner context is cancelled so the callback must stop touching shared state.
Source
Thrown at internal/common/redislock/token_lock.go:19
// Package redislock provides token-owned Redis locks with atomic renewal and
// release. Callers must treat loss of ownership as loss of exclusive access.
package redislock
import (
"context"
"crypto/rand"
"encoding/hex"
"errors"
"fmt"
"time"
"github.com/redis/go-redis/v9"
)
const releaseTimeout = 5 * time.Second
// ErrLockOwnershipLost means exclusive ownership can no longer be guaranteed.
var ErrLockOwnershipLost = errors.New("redis lock ownership lost")
type ownershipContextKey struct{}
var (
releaseScript = redis.NewScript(`
if redis.call('GET', KEYS[1]) == ARGV[1] then
return redis.call('DEL', KEYS[1])
end
return 0
`)
renewScript = redis.NewScript(`
if redis.call('GET', KEYS[1]) == ARGV[1] then
return redis.call('PEXPIRE', KEYS[1], ARGV[2])
end
return 0
`)
)
View on GitHub (pinned to 988cbb0330)
Solutions
- Abort the protected operation; treat all work done after loss of ownership as unsafe and redo it under a fresh lock
- Increase the lease duration or lower the renewal interval if ownership is lost due to slow callbacks
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at internal/common/redislock/token_lock.go:19 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/485eca3cefeded59.
Report an issue: GitHub.