{"record":{"id":"a3a6297344382c2a","repo":"App-vNext/Polly","slug":"seconds-a3a629","errorCode":null,"errorMessage":"seconds","messagePattern":"seconds","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Polly/Timeout/AsyncTimeoutTResultSyntax.cs","lineNumber":63,"sourceCode":"\n        return TimeoutAsync<TResult>(_ => TimeSpan.FromSeconds(seconds), TimeoutStrategy.Optimistic, onTimeoutAsync);\n    }\n\n    /// <summary>\n    /// Builds an <see cref=\"AsyncPolicy{TResult}\"/> 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    /// <typeparam name=\"TResult\">The type of the result.</typeparam>\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<TResult> TimeoutAsync<TResult>(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<TResult>(_ => TimeSpan.FromSeconds(seconds), TimeoutStrategy.Optimistic, onTimeoutAsync);\n    }\n\n    /// <summary>\n    /// Builds an <see cref=\"AsyncPolicy{TResult}\"/> 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    /// <typeparam name=\"TResult\">The type of the result.</typeparam>\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<TResult> TimeoutAsync<TResult>(int seconds, TimeoutStrategy timeoutStrategy, Func<Context, TimeSpan, Task, Task> onTimeoutAsync)\n    {","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly/Timeout/AsyncTimeoutTResultSyntax.cs#L45-L81","documentation":"Thrown by the generic TimeoutAsync<TResult>(int seconds, ...) overload when seconds <= 0. The overload hard-codes TimeoutStrategy.Optimistic and forwards to the provider-based overload, but only after guarding seconds. It is a construction-time range check, not a runtime timeout.","triggerScenarios":"Calling Policy.TimeoutAsync<TResult>(0, onTimeoutAsync), Policy.TimeoutAsync<TResult>(-1, onTimeoutAsync), or any non-positive int. Commonly hit when seconds is read from config or computed and the value is zero/unset.","commonSituations":"Configuration value missing or empty (int.Parse returns 0 default for the field); passing a literal 0 during scaffolding; computed value from subtraction that goes negative under load; downstream of a units mismatch (milliseconds vs seconds).","solutions":["Pass a positive int, e.g. Policy.TimeoutAsync<TResult>(30, onTimeoutAsync).","Validate the source: ensure the config key exists and parses to > 0 before the call.","Switch to the TimeSpan overload if you need sub-second or infinite timeouts."],"exampleFix":"// before\nPolicy.TimeoutAsync<MyResult>(configuredSeconds, onTimeoutAsync); // configuredSeconds == 0\n\n// after\nif (configuredSeconds <= 0) throw new InvalidOperationException(\"timeout misconfigured\");\nPolicy.TimeoutAsync<MyResult>(configuredSeconds, onTimeoutAsync);","handlingStrategy":"validation","validationCode":"if (seconds <= 0) throw new ArgumentOutOfRangeException(nameof(seconds), \"must be > 0\");\nvar policy = Policy.TimeoutAsync<TResult>(seconds, onTimeoutAsync);","typeGuard":"static bool IsValidSeconds(int s) => s > 0;","tryCatchPattern":null,"preventionTips":["Validate config-sourced ints at startup.","Distinguish seconds from milliseconds when computing the value.","Prefer the TimeSpan overload when units are ambiguous."],"tags":["argument-out-of-range","validation","timeout","legacy-api","polly-v7"],"backgroundTag":null,"analyzedSha":"d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac","analyzedAt":"2026-08-13T16:36:01.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}