{"record":{"id":"c15581b118a13a8a","repo":"App-vNext/Polly","slug":"value-must-be-greater-than-or-equal-to-zero","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/AsyncBulkheadSyntax.cs","lineNumber":70,"sourceCode":"    /// <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 BulkheadAsync(\n        int maxParallelization,\n        int maxQueuingActions,\n        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(\n            maxParallelization,\n            maxQueuingActions,\n            onBulkheadRejectedAsync);\n    }\n}\n","sourceCodeStart":52,"sourceCodeEnd":84,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly/Bulkhead/AsyncBulkheadSyntax.cs#L52-L84","documentation":"AsyncBulkheadSyntax.BulkheadAsync throws ArgumentOutOfRangeException(nameof(maxQueuingActions)) when maxQueuingActions < 0. The queue may be empty (0 = no queuing, reject-on-overflow) but never negative; a negative queue length is meaningless.","triggerScenarios":"Calling Policy.BulkheadAsync(maxParallelization: 5, maxQueuingActions: -1) or any negative queue size.","commonSituations":"Config binding that yields -1 as a 'use default' sentinel; arithmetic that subtracts from the queue size; passing an int parsed from user input without bounds checking.","solutions":["Pass maxQueuingActions >= 0 (use 0 to disable queuing).","Clamp config values: maxQueuingActions = Math.Max(0, configured).","Validate input at the configuration boundary."],"exampleFix":"// before\nvar policy = Policy.BulkheadAsync(5, maxQueuingActions: -1);\n\n// after\nvar policy = Policy.BulkheadAsync(5, maxQueuingActions: 0); // no queue","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 explicitly disable queuing rather than negative sentinels.","Validate config values before constructing the policy."],"tags":["bulkhead","legacy","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"}