HangfireIO/Hangfire · error · ArgumentOutOfRangeException
Sliding timeout should be greater than zero
Error message
Sliding timeout should be greater than zero
What it means
SqlServerStorageOptions.SlidingInvisibilityTimeout was set to zero or a negative TimeSpan, which is invalid. The setter requires a strictly positive value and throws ArgumentOutOfRangeException. This optional property controls a sliding visibility window for queued jobs when non-null.
Source
Thrown at src/Hangfire.SqlServer/SqlServerStorageOptions.cs:118
{
throw new ArgumentException(message, nameof(value));
}
_queuePollInterval = value;
}
}
[Obsolete("Does not make sense anymore. Background jobs re-queued instantly even after ungraceful shutdown now. Will be removed in 2.0.0.")]
public TimeSpan InvisibilityTimeout { get; set; }
public TimeSpan? SlidingInvisibilityTimeout
{
get { return _slidingInvisibilityTimeout; }
set
{
if (value <= TimeSpan.Zero)
{
throw new ArgumentOutOfRangeException(nameof(value), "Sliding timeout should be greater than zero");
}
_slidingInvisibilityTimeout = value;
}
}
public bool PrepareSchemaIfNecessary { get; set; }
public TimeSpan JobExpirationCheckInterval
{
get { return _jobExpirationCheckInterval; }
set {
if (value.TotalMilliseconds > int.MaxValue)
{
throw new ArgumentOutOfRangeException(nameof(value), "Job expiration check interval cannot be greater than int.MaxValue");
}
_jobExpirationCheckInterval = value;
}View on GitHub (pinned to c236dd0f93)
Solutions
- Set SlidingInvisibilityTimeout to null to disable sliding visibility (the default), rather than zero.
- If enabling it, use a positive value like TimeSpan.FromMinutes(5).
- Validate configuration-sourced values before assignment.
Example fix
// before options.SlidingInvisibilityTimeout = TimeSpan.Zero; // throws // after — disable by leaving null, or set a positive value options.SlidingInvisibilityTimeout = null; // disabled // or: options.SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5);
Defensive patterns
Strategy: validation
Validate before calling
TimeSpan? sliding = /* from config or null */;
if (sliding.HasValue && sliding.Value <= TimeSpan.Zero)
throw new ArgumentOutOfRangeException(nameof(sliding), "SlidingInvisibilityTimeout must be positive or null.");
options.SlidingInvisibilityTimeout = sliding; Type guard
static bool IsValidSlidingTimeout(TimeSpan? value) => !value.HasValue || value.Value > TimeSpan.Zero;
Prevention
- Use null to disable sliding visibility timeout, not zero.
- Validate config-sourced values before assignment.
- Use positive TimeSpan values like TimeSpan.FromMinutes(5) when enabling.
When it happens
Trigger: Setting SlidingInvisibilityTimeout to TimeSpan.Zero or a negative TimeSpan; passing a computed value that collapses to zero.
Common situations: Disabling sliding timeout by setting it to zero (the correct way is to leave it null); config-driven durations that produce zero; misunderstanding that null means 'disabled'.
Understand the failure class
- Timeouts: ETIMEDOUT, deadlines, and hung requests — what actually expires when a request times out.
Related errors
- The QueuePollInterval property value should be positive. Giv
- Job expiration check interval cannot be greater than int.Max
- Attempts value must be equal or greater than zero.
- DelaysInSeconds value must be an array of non-negative numbe
- WorkerCount property value should be positive.
AI-assisted analysis of HangfireIO/Hangfire@c236dd0f93 (2026-08-13).
Data as JSON: /api/errors/96da992736a3b863.
Report an issue: GitHub.