{"record":{"id":"58a49728ad524175","repo":"App-vNext/Polly","slug":"value-must-be-greater-than-or-equal-to-zero-58a497","errorCode":null,"errorMessage":"Value must be greater than or equal to zero.","messagePattern":"Value must be greater than or equal to zero\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Polly/Bulkhead/AsyncBulkheadTResultSyntax.cs","lineNumber":63,"sourceCode":"    /// </summary>\n    /// <typeparam name=\"TResult\">The type of the result.</typeparam>\n    /// <param name=\"maxParallelization\">The maximum number of concurrent actions that may be executing through the policy.</param>\n    /// <param name=\"maxQueuingActions\">The maximum number of actions that may be queuing, waiting for an execution slot.</param>\n    /// <param name=\"onBulkheadRejectedAsync\">An action to call asynchronously, if the bulkhead rejects execution due to oversubscription.</param>\n    /// <returns>The policy instance.</returns>\n    /// <exception cref=\"ArgumentOutOfRangeException\">maxParallelization;Value must be greater than zero.</exception>\n    /// <exception cref=\"ArgumentOutOfRangeException\">maxQueuingActions;Value must be greater than or equal to zero.</exception>\n    /// <exception cref=\"ArgumentNullException\">Thrown when <paramref name=\"onBulkheadRejectedAsync\"/> is <see langword=\"null\"/>.</exception>\n    public static AsyncBulkheadPolicy<TResult> BulkheadAsync<TResult>(int maxParallelization, int maxQueuingActions, Func<Context, Task> onBulkheadRejectedAsync)\n    {\n        if (maxParallelization <= 0)\n        {\n            throw new ArgumentOutOfRangeException(nameof(maxParallelization), \"Value must be greater than zero.\");\n        }\n\n        if (maxQueuingActions < 0)\n        {\n            throw new ArgumentOutOfRangeException(nameof(maxQueuingActions), \"Value must be greater than or equal to zero.\");\n        }\n\n        if (onBulkheadRejectedAsync == null)\n        {\n            throw new ArgumentNullException(nameof(onBulkheadRejectedAsync));\n        }\n\n        return new AsyncBulkheadPolicy<TResult>(\n            maxParallelization,\n            maxQueuingActions,\n            onBulkheadRejectedAsync);\n    }\n\n    private static Task EmptyHandler(Context context) => TaskHelper.EmptyTask;\n}\n","sourceCodeStart":45,"sourceCodeEnd":79,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly/Bulkhead/AsyncBulkheadTResultSyntax.cs#L45-L79","documentation":"AsyncBulkheadTResultSyntax.BulkheadAsync<TResult> throws ArgumentOutOfRangeException(nameof(maxQueuingActions)) when maxQueuingActions < 0. Generic legacy bulkhead mirror of the non-generic check: the queue may be zero but not negative.","triggerScenarios":"Calling Policy<T>.BulkheadAsync(5, maxQueuingActions: -1) or any negative value.","commonSituations":"Config sentinel of -1 misread as 'default'; arithmetic that subtracts from queue length; unvalidated user input.","solutions":["Pass maxQueuingActions >= 0 (0 disables queuing).","Clamp: Math.Max(0, configured).","Validate at the configuration boundary."],"exampleFix":"// before\nvar policy = Policy<string>.BulkheadAsync(5, maxQueuingActions: -1);\n\n// after\nvar policy = Policy<string>.BulkheadAsync(5, maxQueuingActions: 0);","handlingStrategy":"validation","validationCode":"if (maxQueuingActions < 0) {\n    throw new ArgumentOutOfRangeException(nameof(maxQueuingActions), \"Use zero or a positive value.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp queue size with Math.Max(0, value).","Use 0 to disable queuing instead of negative sentinels.","Validate config values before constructing the policy."],"tags":["bulkhead","legacy","generic","argument-out-of-range","validation","polly-v7"],"backgroundTag":null,"analyzedSha":"d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac","analyzedAt":"2026-08-13T16:36:01.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}