{"record":{"id":"f2308cc1a72c4a99","repo":"App-vNext/Polly","slug":"value-must-be-greater-than-or-equal-to-zero-f2308c","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/BulkheadSyntax.cs","lineNumber":60,"sourceCode":"    /// <para>When an execution would cause the number of actions executing concurrently through the policy to exceed <paramref name=\"maxParallelization\" />, the policy allows a further <paramref name=\"maxQueuingActions\" /> executions to queue, waiting for a concurrent execution slot.  When an execution would cause the number of queuing actions to exceed <paramref name=\"maxQueuingActions\" />, a <see cref=\"BulkheadRejectedException\" /> is thrown.</para>\n    /// </summary>\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=\"onBulkheadRejected\">An action to call, 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=\"onBulkheadRejected\"/> is <see langword=\"null\"/>.</exception>\n    public static BulkheadPolicy Bulkhead(int maxParallelization, int maxQueuingActions, Action<Context> onBulkheadRejected)\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 (onBulkheadRejected == null)\n        {\n            throw new ArgumentNullException(nameof(onBulkheadRejected));\n        }\n\n        return new BulkheadPolicy(\n            maxParallelization,\n            maxQueuingActions,\n            onBulkheadRejected);\n    }\n\n    private static void EmptyAction(Context context)\n    {\n        // No-op\n    }\n}","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly/Bulkhead/BulkheadSyntax.cs#L42-L78","documentation":"Thrown as ArgumentOutOfRangeException(nameof(maxQueuingActions)) when constructing a non-generic BulkheadPolicy via Policy.Bulkhead(...) with maxQueuingActions < 0. The guard at BulkheadSyntax.cs:60–64 fires at construction time. A value of 0 is valid (no queuing — immediate rejection on overflow), but negative values are rejected.","triggerScenarios":"Calling Policy.Bulkhead(maxParallelization, maxQueuingActions, ...) where maxQueuingActions is negative. Happens when the value is parsed from configuration or computed in a way that yields a negative number.","commonSituations":"Subtracting a buffer from maxQueuingActions that overshoots into negatives. Configuration typo or missing key yielding a parsed negative. Off-by-one in a formula calculating queue depth.","solutions":["Set maxQueuingActions to 0 or a positive integer (0 means no queue, requests are rejected immediately when parallelization is full)","Clamp the computed value: Math.Max(0, computedQueue)","Validate at startup and apply a sensible default if the value is invalid"],"exampleFix":"// before\nint queue = desiredQueue - buffer; // could go negative\nvar policy = Policy.Bulkhead(10, queue, _ => { }); // throws if buffer > desiredQueue\n\n// after\nint queue = Math.Max(0, desiredQueue - buffer);\nvar policy = Policy.Bulkhead(10, queue, _ => { });","handlingStrategy":"validation","validationCode":"int safeQueue = Math.Max(0, maxQueuingActions);\nvar policy = Policy.Bulkhead(maxParallelization, safeQueue, onReject);","typeGuard":"public static bool IsValidQueueDepth(int value) => value >= 0;","tryCatchPattern":null,"preventionTips":["Clamp computed queue depths to 0 rather than trusting arithmetic to stay non-negative","Validate configuration at startup with clear error messages","Use Math.Max(0, value) as a defensive floor in configuration parsing"],"tags":["bulkhead","configuration","argument-validation","out-of-range","construction"],"backgroundTag":null,"analyzedSha":"d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac","analyzedAt":"2026-08-13T16:36:01.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}