Tencent/WeKnora · error

redis lock renewal interval must be positive and shorter tha

Error message

redis lock renewal interval must be positive and shorter than the lease

What it means

Argument guard raised by WithRenewableLock when renewInterval is zero/negative or not strictly shorter than the lease — such a configuration either never renews or races the lease expiry, breaking safe renewal. Configuration validation before acquiring.

Source

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

	}
	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)
	go renewLoop(
		renewCtx,
		cancelLock,

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Set renewInterval to a positive duration meaningfully shorter than the lease (e.g. lease/3)
  2. Fix the lock configuration constants passed by callers like withConfigLock
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/common/redislock/token_lock.go:165 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/87c50997d2a18942. Report an issue: GitHub.