{"record":{"id":"428f2d996a1fe2a6","repo":"HangfireIO/Hangfire","slug":"timeout-value-must-be-equal-or-greater-than-zero","errorCode":null,"errorMessage":"Timeout value must be equal or greater than zero.","messagePattern":"Timeout value must be equal or greater than zero\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/LatencyTimeoutAttribute.cs","lineNumber":47,"sourceCode":"    public sealed class LatencyTimeoutAttribute : JobFilterAttribute, IElectStateFilter\n    {\n        private readonly ILog _logger = LogProvider.For<LatencyTimeoutAttribute>();\n\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"LatencyTimeoutAttribute\"/>\n        /// class with the given timeout value.\n        /// </summary>\n        /// <param name=\"timeoutInSeconds\">Non-negative timeout value in seconds \n        /// that will be used to determine whether to delete a job.</param>\n        /// \n        /// <exception cref=\"ArgumentOutOfRangeException\">\n        ///   <paramref name=\"timeoutInSeconds\"/> has a negative value.\n        /// </exception>\n        public LatencyTimeoutAttribute(int timeoutInSeconds)\n        {\n            if (timeoutInSeconds < 0)\n            {\n                throw new ArgumentOutOfRangeException(nameof(timeoutInSeconds), \"Timeout value must be equal or greater than zero.\");\n            }\n\n            TimeoutInSeconds = timeoutInSeconds;\n            LogLevel = LogLevel.Debug;\n        }\n\n        /// <summary>\n        /// Gets or sets a level for log message that will be produced, when a\n        /// background job was deleted due to exceeded timeout.\n        /// </summary>\n        public LogLevel LogLevel { get; set; }\n        public int TimeoutInSeconds { get; }\n\n        /// <inheritdoc />\n        public void OnStateElection(ElectStateContext context)\n        {\n            var state = context.CandidateState as ProcessingState;\n            if (state == null)","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/LatencyTimeoutAttribute.cs#L29-L65","documentation":"Thrown by the LatencyTimeoutAttribute constructor when timeoutInSeconds is negative. This attribute deletes jobs that exceed a specified latency (time in processing queue); a negative timeout is logically invalid since it would delete all jobs immediately.","triggerScenarios":"Decorating a job method with [LatencyTimeout(-1)] or passing a computed negative value. Since this is an attribute, the value must be a compile-time constant, so a negative literal is required to trigger it.","commonSituations":"A typo or incorrect calculation leading to a negative literal in the attribute, or confusion about the unit (passing milliseconds as seconds). Extremely rare since attribute arguments are compile-time constants.","solutions":["Use a non-negative integer: [LatencyTimeout(30)] for a 30-second timeout","Use [LatencyTimeout(0)] if you want immediate deletion of any delayed job","Review the timeout value semantics: it is in seconds, not milliseconds"],"exampleFix":"// before\n[LatencyTimeout(-5)]\npublic void ProcessOrder(int orderId) { }\n\n// after\n[LatencyTimeout(5)]\npublic void ProcessOrder(int orderId) { }","handlingStrategy":"validation","validationCode":"// Attribute arguments are compile-time constants - validate at code review\n// Ensure [LatencyTimeout(N)] always has N >= 0","typeGuard":"timeoutInSeconds >= 0","tryCatchPattern":null,"preventionTips":["Always use non-negative integer literals in the LatencyTimeout attribute","Use code review to catch negative values since attributes use compile-time constants","Remember the unit is seconds, not milliseconds"],"tags":["argument-out-of-range","attribute","job-filter","validation","hangfire"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}