Tencent/WeKnora · error

redis lock callback is required

Error message

redis lock callback is required

What it means

Argument guard raised by redislock.WithRenewableLock when fn is nil — there is no callback to run under the lock, so acquisition is pointless and refused before touching Redis. Programming-error guard.

Source

Thrown at internal/common/redislock/token_lock.go:162

	).Int64()
	if err != nil {
		return false, fmt.Errorf("renew redis lock %q: %w", key, err)
	}
	return renewed != 0, nil
}

// WithRenewableLock acquires key, renews it while fn runs, and atomically
// releases it on exit. Renewal failure cancels the context passed to fn.
func WithRenewableLock(
	ctx context.Context,
	client redis.UniversalClient,
	key string,
	lease time.Duration,
	renewInterval time.Duration,
	fn func(context.Context) error,
) (resultErr error) {
	if fn == nil {
		return errors.New("redis lock callback is required")
	}
	if renewInterval <= 0 || renewInterval >= lease {
		return errors.New("redis lock renewal interval must be positive and shorter than the lease")
	}

	token, err := NewToken()
	if err != nil {
		return err
	}
	if err := Acquire(ctx, client, key, token, lease); err != nil {
		return err
	}

	lockCtx, cancelLock := context.WithCancelCause(ctx)
	ownershipCtx, cancelOwnership := context.WithCancelCause(context.Background())
	lockCtx = context.WithValue(lockCtx, ownershipContextKey{}, ownershipCtx)
	renewCtx, stopRenewal := context.WithCancel(context.WithoutCancel(ctx))
	renewResult := make(chan error, 1)

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Pass a non-nil callback to WithRenewableLock
  2. Check the call site — a nil fn usually means an uninitialized closure or a misconfigured code path
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/common/redislock/token_lock.go:162 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/8d720f225213f430. Report an issue: GitHub.