{"record":{"id":"18c268788860e1de","repo":"App-vNext/Polly","slug":"seconds","errorCode":null,"errorMessage":"seconds","messagePattern":"seconds","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Polly/Timeout/AsyncTimeoutSyntax.cs","lineNumber":58,"sourceCode":"    {\n        TimeoutValidator.ValidateSecondsTimeout(seconds);\n        return TimeoutAsync(_ => TimeSpan.FromSeconds(seconds), TimeoutStrategy.Optimistic, onTimeoutAsync);\n    }\n\n    /// <summary>\n    /// Builds an <see cref=\"AsyncPolicy\"/> that will wait asynchronously for a delegate to complete for a specified period of time. A <see cref=\"TimeoutRejectedException\"/> will be thrown if the delegate does not complete within the configured timeout.\n    /// </summary>\n    /// <param name=\"seconds\">The number of seconds after which to timeout.</param>\n    /// <param name=\"onTimeoutAsync\">An action to call on timeout, passing the execution context, the timeout applied, the <see cref=\"Task\"/> capturing the abandoned, timed-out action, and the captured <see cref=\"Exception\"/>.\n    /// <remarks>The Task parameter will be null if the executed action responded cooperatively to cancellation before the policy timed it out.</remarks></param>\n    /// <returns>The policy instance.</returns>\n    /// <exception cref=\"ArgumentOutOfRangeException\">seconds;Value must be greater than zero.</exception>\n    /// <exception cref=\"ArgumentNullException\">Thrown when <paramref name=\"onTimeoutAsync\"/> is <see langword=\"null\"/>.</exception>\n    public static AsyncTimeoutPolicy TimeoutAsync(int seconds, Func<Context, TimeSpan, Task, Exception, Task> onTimeoutAsync)\n    {\n        if (seconds <= 0)\n        {\n            throw new ArgumentOutOfRangeException(nameof(seconds));\n        }\n\n        return TimeoutAsync(_ => TimeSpan.FromSeconds(seconds), TimeoutStrategy.Optimistic, onTimeoutAsync);\n    }\n\n    /// <summary>\n    /// Builds an <see cref=\"AsyncPolicy\" /> that will wait asynchronously for a delegate to complete for a specified period of time. A <see cref=\"TimeoutRejectedException\" /> will be thrown if the delegate does not complete within the configured timeout.\n    /// </summary>\n    /// <param name=\"seconds\">The number of seconds after which to timeout.</param>\n    /// <param name=\"timeoutStrategy\">The timeout strategy.</param>\n    /// <param name=\"onTimeoutAsync\">An action to call on timeout, passing the execution context, the timeout applied, and a <see cref=\"Task\" /> capturing the abandoned, timed-out action.\n    /// <remarks>The Task parameter will be null if the executed action responded cooperatively to cancellation before the policy timed it out.</remarks></param>\n    /// <returns>The policy instance.</returns>\n    /// <exception cref=\"ArgumentOutOfRangeException\">seconds;Value must be greater than zero.</exception>\n    /// <exception cref=\"ArgumentNullException\">Thrown when <paramref name=\"onTimeoutAsync\"/> is <see langword=\"null\"/>.</exception>\n    public static AsyncTimeoutPolicy TimeoutAsync(int seconds, TimeoutStrategy timeoutStrategy, Func<Context, TimeSpan, Task, Task> onTimeoutAsync)\n    {\n        TimeoutValidator.ValidateSecondsTimeout(seconds);","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly/Timeout/AsyncTimeoutSyntax.cs#L40-L76","documentation":"ArgumentOutOfRangeException (ParamName \"seconds\") is thrown at configuration time by TimeoutAsync(int seconds, Func<Context,TimeSpan,Task,Exception,Task> onTimeoutAsync) when seconds <= 0 (AsyncTimeoutSyntax.cs:56-59). Unlike sibling overloads that call TimeoutValidator.ValidateSecondsTimeout, this overload uses a direct `if (seconds <= 0)` check and throws with the generic message-less constructor. A timeout must be strictly positive.","triggerScenarios":"Policy.TimeoutAsync(0, onTimeoutAsync) or Policy.TimeoutAsync(-1, onTimeoutAsync) — any seconds value that is zero or negative.","commonSituations":"A timeout value read from configuration that defaulted to 0 when the key was missing; arithmetic that produces zero or a negative number (e.g. subtraction of buffers); passing Timeout.Infinite (a negative int) by mistake into the seconds overload instead of the TimeSpan overload.","solutions":["Pass a positive integer seconds value, e.g. Policy.TimeoutAsync(30, onTimeoutAsync).","If the value comes from config, validate it is > 0 before calling and fall back to a sane default.","For 'no timeout', use the TimeSpan overload with System.Threading.Timeout.InfiniteTimeSpan rather than a negative seconds value."],"exampleFix":"// before\nint seconds = int.Parse(config[\"TimeoutSeconds\"]); // 0 when missing\nvar policy = Policy.TimeoutAsync(seconds, onTimeoutAsync);\n\n// after\nint seconds = int.TryParse(config[\"TimeoutSeconds\"], out var s) && s > 0 ? s : 30;\nvar policy = Policy.TimeoutAsync(seconds, onTimeoutAsync);","handlingStrategy":"validation","validationCode":"if (seconds <= 0) throw new InvalidOperationException($\"Timeout seconds must be > 0, got {seconds}.\");\nvar policy = Policy.TimeoutAsync(seconds, onTimeoutAsync);","typeGuard":"static bool IsValidSeconds(int seconds) => seconds > 0;","tryCatchPattern":null,"preventionTips":["Bound config-sourced seconds to a sane default (> 0) when parsing fails or yields zero.","Use the TimeSpan overload with System.Threading.Timeout.InfiniteTimeSpan to express 'no timeout' rather than a negative int.","Add a unit test asserting the configured timeout is positive."],"tags":["argumentoutofrangeexception","timeout","configuration","validation","polly"],"backgroundTag":null,"analyzedSha":"d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac","analyzedAt":"2026-08-13T16:36:01.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}