{"record":{"id":"1695f3297be51bc5","repo":"HangfireIO/Hangfire","slug":"servertimeout-must-be-either-non-negative-and-equa-1695f3","errorCode":null,"errorMessage":"ServerTimeout must be either non-negative and equal to or less than {ServerWatchdog.MaxServerTimeout.Hours} hours","messagePattern":"ServerTimeout must be either non-negative and equal to or less than (.+?) hours","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/Obsolete/ServerWatchdogOptions.cs","lineNumber":41,"sourceCode":"    public class ServerWatchdogOptions\n    {\n        private TimeSpan _serverTimeout;\n        private TimeSpan _checkInterval;\n\n        public ServerWatchdogOptions()\n        {\n            ServerTimeout = ServerWatchdog.DefaultServerTimeout;\n            CheckInterval = ServerWatchdog.DefaultCheckInterval;\n        }\n\n        public TimeSpan ServerTimeout\n        {\n            get { return _serverTimeout; }\n            set\n            {\n                if (value < TimeSpan.Zero || value > ServerWatchdog.MaxServerTimeout)\n                {\n                    throw new ArgumentOutOfRangeException(nameof(value), $\"ServerTimeout must be either non-negative and equal to or less than {ServerWatchdog.MaxServerTimeout.Hours} hours\");\n                }\n\n                _serverTimeout = value;\n            }\n        }\n\n        public TimeSpan CheckInterval\n        {\n            get { return _checkInterval; }\n            set\n            {\n                if (value < TimeSpan.Zero || value > ServerWatchdog.MaxServerCheckInterval)\n                {\n                    throw new ArgumentOutOfRangeException(nameof(value), $\"CheckInterval must be either non-negative and equal to or less than {ServerWatchdog.MaxServerCheckInterval.Hours} hours\");\n\n                };\n                _checkInterval = value;\n            }","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/Obsolete/ServerWatchdogOptions.cs#L23-L59","documentation":"Thrown as ArgumentOutOfRangeException by the obsolete ServerWatchdogOptions.ServerTimeout setter when the supplied TimeSpan is negative or exceeds ServerWatchdog.MaxServerTimeout (24 hours). The watchdog uses this timeout to consider a server dead if it stops heartbeating; an out-of-range value would either mark healthy servers as dead (too small) or never reap stuck servers (too large), so the setter rejects it at line 41.","triggerScenarios":"Setting options.ServerTimeout to a value where value < TimeSpan.Zero or value > TimeSpan.FromHours(24). E.g. options.ServerTimeout = TimeSpan.FromHours(25), or a negative TimeSpan from a miscomputed configuration value.","commonSituations":"A configuration value (e.g. from appsettings) parsed as hours/minutes and multiplied incorrectly producing >24h; a negative TimeSpan from a subtraction that underflows; copying a ServerCheckInterval value into ServerTimeout by mistake where intervals differ; deployment across machines with clock or locale quirks in TimeSpan parsing.","solutions":["Use the non-obsolete BackgroundJobServerOptions.ServerTimeout instead, which enforces the same bounds (0..24h) and is the supported configuration surface.","Clamp or validate the configured TimeSpan to the [TimeSpan.Zero, TimeSpan.FromHours(24)] range before assignment.","If reading from configuration, parse explicitly (TimeSpan.Parse) and log the resolved value to catch unit or magnitude errors early."],"exampleFix":"// before\nwatchdog.ServerTimeout = TimeSpan.FromHours(25); // throws\n\n// after\nvar timeout = TimeSpan.FromMinutes(cfg.TimeoutMinutes);\nserverOptions.ServerTimeout = timeout > ServerWatchdog.MaxServerTimeout\n    ? ServerWatchdog.MaxServerTimeout : timeout;","handlingStrategy":"validation","validationCode":"var timeout = TimeSpan.FromMinutes(cfg.TimeoutMinutes);\nif (timeout < TimeSpan.Zero || timeout > ServerWatchdog.MaxServerTimeout)\n    throw new ArgumentOutOfRangeException(nameof(timeout));\noptions.ServerTimeout = timeout;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use BackgroundJobServerOptions.ServerTimeout (non-obsolete) instead of ServerWatchdogOptions.","Clamp configured TimeSpans to [Zero, MaxServerTimeout] and log the resolved value.","Parse config with explicit units (TimeSpan.FromMinutes/FromSeconds) to avoid magnitude errors."],"tags":["argument-out-of-range","configuration","server","watchdog","obsolete"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}