{"record":{"id":"e22ef8f9831a92a2","repo":"HangfireIO/Hangfire","slug":"shutdowntimeout-must-be-either-equal-to-or-less-th","errorCode":null,"errorMessage":"ShutdownTimeout must be either equal to or less than {Int32.MaxValue} milliseconds and non-negative or infinite","messagePattern":"ShutdownTimeout must be either equal to or less than (.+?) milliseconds and non-negative or infinite","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/BackgroundJobServerOptions.cs","lineNumber":110,"sourceCode":"            get => _stopTimeout;\n            set\n            {\n                if ((value < TimeSpan.Zero && value != Timeout.InfiniteTimeSpan) || value.TotalMilliseconds > Int32.MaxValue)\n                {\n                    throw new ArgumentOutOfRangeException(nameof(value), $\"StopTimeout must be either equal to or less than {Int32.MaxValue} milliseconds and non-negative or infinite\");\n                }\n                _stopTimeout = value;\n            }\n        }\n\n        public TimeSpan ShutdownTimeout\n        {\n            get { return _shutdownTimeout; }\n            set\n            {\n                if ((value < TimeSpan.Zero && value != Timeout.InfiniteTimeSpan) || value.TotalMilliseconds > Int32.MaxValue)\n                {\n                    throw new ArgumentOutOfRangeException(nameof(value), $\"ShutdownTimeout must be either equal to or less than {Int32.MaxValue} milliseconds and non-negative or infinite\");\n                }\n                _shutdownTimeout = value;\n            }\n        }\n\n        public TimeSpan SchedulePollingInterval\n        {\n            get { return _schedulePollingInterval; }\n            set\n            {\n                if (value < TimeSpan.Zero || value.TotalMilliseconds > Int32.MaxValue)\n                {\n                    throw new ArgumentOutOfRangeException(nameof(value), $\"SchedulePollingInterval must be non-negative and either equal to or less than {Int32.MaxValue} milliseconds\");\n                }\n\n                _schedulePollingInterval = value;\n            }\n        }","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/BackgroundJobServerOptions.cs#L92-L128","documentation":"This ArgumentOutOfRangeException(\"value\", \"ShutdownTimeout must be either equal to or less than Int32.MaxValue milliseconds and non-negative or infinite\") is thrown by the ShutdownTimeout setter of BackgroundJobServerOptions. Same rule as StopTimeout: reject negative (unless exactly Timeout.InfiniteTimeSpan) or values over Int32.MaxValue total milliseconds. ShutdownTimeout bounds how long the server waits during a full shutdown before abandoning jobs.","triggerScenarios":"Assigning a negative ShutdownTimeout that is not Timeout.InfiniteTimeSpan; assigning a TimeSpan whose TotalMilliseconds exceeds Int32.MaxValue; binding an out-of-range value from configuration.","commonSituations":"Config typos producing negative values; unit confusion (seconds vs milliseconds) causing overflow; binding TimeSpan.MaxValue; intending to wait forever but writing TimeSpan.MaxValue instead of Timeout.InfiniteTimeSpan.","solutions":["Use Timeout.InfiniteTimeSpan to wait indefinitely, or a non-negative TimeSpan within Int32.MaxValue ms.","Clamp the bound value into the legal range.","Leave the property unset to use the default (BackgroundProcessingServer.DefaultShutdownTimeout).","Validate the configured value at startup."],"exampleFix":"// before\noptions.ShutdownTimeout = TimeSpan.MaxValue; // TotalMilliseconds over Int32.MaxValue\n\n// after\noptions.ShutdownTimeout = Timeout.InfiniteTimeSpan; // wait forever, legal","handlingStrategy":"validation","validationCode":"TimeSpan SanitizeTimeout(TimeSpan ts) =>\n    ts == Timeout.InfiniteTimeSpan || (ts >= TimeSpan.Zero && ts.TotalMilliseconds <= int.MaxValue)\n        ? ts : BackgroundProcessingServer.DefaultShutdownTimeout;\noptions.ShutdownTimeout = SanitizeTimeout(parsed);","typeGuard":"static bool IsValidTimeout(TimeSpan ts) => ts == Timeout.InfiniteTimeSpan || (ts >= TimeSpan.Zero && ts.TotalMilliseconds <= int.MaxValue);","tryCatchPattern":"try { options.ShutdownTimeout = parsed; }\ncatch (ArgumentOutOfRangeException) { options.ShutdownTimeout = BackgroundProcessingServer.DefaultShutdownTimeout; }","preventionTips":["Use Timeout.InfiniteTimeSpan, not TimeSpan.MaxValue.","Clamp bound values.","Check config units."],"tags":["csharp","hangfire","argumentoutofrangeexception","configuration","timeout","validation","background-jobs"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}