{"record":{"id":"2fc463120aa1dd50","repo":"App-vNext/Polly","slug":"the-number-of-executions-per-timespan-must-be-posi-2fc463","errorCode":null,"errorMessage":"The number of executions per timespan must be positive.","messagePattern":"The number of executions per timespan must be positive\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Polly/RateLimit/RateLimitTResultSyntax.cs","lineNumber":85,"sourceCode":"        {\n            throw new ArgumentOutOfRangeException(nameof(numberOfExecutions), numberOfExecutions, $\"{nameof(numberOfExecutions)} per timespan must be an integer greater than or equal to 1.\");\n        }\n\n        if (perTimeSpan <= TimeSpan.Zero)\n        {\n            throw new ArgumentOutOfRangeException(nameof(perTimeSpan), perTimeSpan, $\"{nameof(perTimeSpan)} must be a positive timespan.\");\n        }\n\n        if (maxBurst < 1)\n        {\n            throw new ArgumentOutOfRangeException(nameof(maxBurst), maxBurst, $\"{nameof(maxBurst)} must be an integer greater than or equal to 1.\");\n        }\n\n        var onePer = TimeSpan.FromTicks(perTimeSpan.Ticks / numberOfExecutions);\n\n        if (onePer <= TimeSpan.Zero)\n        {\n            throw new ArgumentOutOfRangeException(nameof(perTimeSpan), perTimeSpan, \"The number of executions per timespan must be positive.\");\n        }\n\n        IRateLimiter rateLimiter = new LockFreeTokenBucketRateLimiter(onePer, maxBurst);\n\n        return new RateLimitPolicy<TResult>(rateLimiter, retryAfterFactory);\n    }\n}\n","sourceCodeStart":67,"sourceCodeEnd":93,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly/RateLimit/RateLimitTResultSyntax.cs#L67-L93","documentation":"Thrown by RateLimitTResultSyntax.RateLimit<TResult> when the derived per-token interval onePer (perTimeSpan.Ticks / numberOfExecutions) rounds down to zero. The generic overload computes the same refill interval as the non-generic one and guards against an unusable sub-tick interval.","triggerScenarios":"A combination where perTimeSpan.Ticks / numberOfExecutions <= 0 in the generic overload — e.g. very high execution count against a sub-tick window.","commonSituations":"High-throughput generic policies; unit mismatch between config and TimeSpan; integer division flooring to zero.","solutions":["Increase perTimeSpan so each token represents at least 1 tick (100ns).","Reduce numberOfExecutions to keep the per-token interval positive.","Confirm the time unit and tick math at config time."],"exampleFix":"// before\nvar policy = Policy.RateLimit<MyResult>(10000, TimeSpan.FromTicks(1), 10000, factory);\n// after\nvar policy = Policy.RateLimit<MyResult>(10000, TimeSpan.FromSeconds(1), 10000, factory);","handlingStrategy":"validation","validationCode":"if (perTimeSpan.Ticks / numberOfExecutions < 1) throw new InvalidOperationException(\"perTimeSpan too short for the configured execution count.\");\nvar policy = Policy.RateLimit<TResult>(numberOfExecutions, perTimeSpan, maxBurst, retryAfterFactory);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep perTimeSpan.Ticks / numberOfExecutions >= 1 for high-throughput typed limits.","Remember tick granularity is 100ns.","Add unit tests for extreme count/window combinations."],"tags":["rate-limit","argumentoutofrange","generic","token-bucket","integer-overflow"],"backgroundTag":null,"analyzedSha":"d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac","analyzedAt":"2026-08-13T16:36:01.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}