{"record":{"id":"87c50997d2a18942","repo":"Tencent/WeKnora","slug":"redis-lock-renewal-interval-must-be-positive-and-s","errorCode":null,"errorMessage":"redis lock renewal interval must be positive and shorter than the lease","messagePattern":"redis lock renewal interval must be positive and shorter than the lease","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/common/redislock/token_lock.go","lineNumber":165,"sourceCode":"\t}\n\treturn renewed != 0, nil\n}\n\n// WithRenewableLock acquires key, renews it while fn runs, and atomically\n// releases it on exit. Renewal failure cancels the context passed to fn.\nfunc WithRenewableLock(\n\tctx context.Context,\n\tclient redis.UniversalClient,\n\tkey string,\n\tlease time.Duration,\n\trenewInterval time.Duration,\n\tfn func(context.Context) error,\n) (resultErr error) {\n\tif fn == nil {\n\t\treturn errors.New(\"redis lock callback is required\")\n\t}\n\tif renewInterval <= 0 || renewInterval >= lease {\n\t\treturn errors.New(\"redis lock renewal interval must be positive and shorter than the lease\")\n\t}\n\n\ttoken, err := NewToken()\n\tif err != nil {\n\t\treturn err\n\t}\n\tif err := Acquire(ctx, client, key, token, lease); err != nil {\n\t\treturn err\n\t}\n\n\tlockCtx, cancelLock := context.WithCancelCause(ctx)\n\townershipCtx, cancelOwnership := context.WithCancelCause(context.Background())\n\tlockCtx = context.WithValue(lockCtx, ownershipContextKey{}, ownershipCtx)\n\trenewCtx, stopRenewal := context.WithCancel(context.WithoutCancel(ctx))\n\trenewResult := make(chan error, 1)\n\tgo renewLoop(\n\t\trenewCtx,\n\t\tcancelLock,","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/common/redislock/token_lock.go#L147-L183","documentation":"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.","triggerScenarios":"Thrown at internal/common/redislock/token_lock.go:165 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set renewInterval to a positive duration meaningfully shorter than the lease (e.g. lease/3)","Fix the lock configuration constants passed by callers like withConfigLock"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}