HangfireIO/Hangfire · error · ArgumentOutOfRangeException

Timeout value must be equal or greater than zero.

Error message

Timeout value must be equal or greater than zero.

What it means

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.

Source

Thrown at src/Hangfire.Core/LatencyTimeoutAttribute.cs:47

    public sealed class LatencyTimeoutAttribute : JobFilterAttribute, IElectStateFilter
    {
        private readonly ILog _logger = LogProvider.For<LatencyTimeoutAttribute>();

        /// <summary>
        /// Initializes a new instance of the <see cref="LatencyTimeoutAttribute"/>
        /// class with the given timeout value.
        /// </summary>
        /// <param name="timeoutInSeconds">Non-negative timeout value in seconds 
        /// that will be used to determine whether to delete a job.</param>
        /// 
        /// <exception cref="ArgumentOutOfRangeException">
        ///   <paramref name="timeoutInSeconds"/> has a negative value.
        /// </exception>
        public LatencyTimeoutAttribute(int timeoutInSeconds)
        {
            if (timeoutInSeconds < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(timeoutInSeconds), "Timeout value must be equal or greater than zero.");
            }

            TimeoutInSeconds = timeoutInSeconds;
            LogLevel = LogLevel.Debug;
        }

        /// <summary>
        /// Gets or sets a level for log message that will be produced, when a
        /// background job was deleted due to exceeded timeout.
        /// </summary>
        public LogLevel LogLevel { get; set; }
        public int TimeoutInSeconds { get; }

        /// <inheritdoc />
        public void OnStateElection(ElectStateContext context)
        {
            var state = context.CandidateState as ProcessingState;
            if (state == null)

View on GitHub (pinned to c236dd0f93)

Solutions

  1. Use a non-negative integer: [LatencyTimeout(30)] for a 30-second timeout
  2. Use [LatencyTimeout(0)] if you want immediate deletion of any delayed job
  3. Review the timeout value semantics: it is in seconds, not milliseconds

Example fix

// before
[LatencyTimeout(-5)]
public void ProcessOrder(int orderId) { }

// after
[LatencyTimeout(5)]
public void ProcessOrder(int orderId) { }
Defensive patterns

Strategy: validation

Validate before calling

// Attribute arguments are compile-time constants - validate at code review
// Ensure [LatencyTimeout(N)] always has N >= 0

Type guard

timeoutInSeconds >= 0

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Related errors


AI-assisted analysis of HangfireIO/Hangfire@c236dd0f93 (2026-08-13). Data as JSON: /api/errors/428f2d996a1fe2a6. Report an issue: GitHub.