{"record":{"id":"5883a0c7f7e2c2fd","repo":"HangfireIO/Hangfire","slug":"stoptimeout-must-be-either-equal-to-or-less-than","errorCode":null,"errorMessage":"StopTimeout must be either equal to or less than {Int32.MaxValue} milliseconds and non-negative or infinite","messagePattern":"StopTimeout 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":97,"sourceCode":"        {\n            get { return _queues; }\n            set\n            {\n                if (value == null) throw new ArgumentNullException(nameof(value));\n                if (value.Length == 0) throw new ArgumentException(\"You should specify at least one queue to listen.\", nameof(value));\n\n                _queues = value;\n            }\n        }\n\n        public TimeSpan StopTimeout\n        {\n            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","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/BackgroundJobServerOptions.cs#L79-L115","documentation":"This ArgumentOutOfRangeException(\"value\", \"StopTimeout must be either equal to or less than Int32.MaxValue milliseconds and non-negative or infinite\") is thrown by the StopTimeout setter of BackgroundJobServerOptions. The setter rejects any value that is negative (unless it equals Timeout.InfiniteTimeSpan) or whose total milliseconds exceed Int32.MaxValue. StopTimeout bounds how long the processing server waits for currently-running jobs to finish when stopping.","triggerScenarios":"Assigning options.StopTimeout = TimeSpan.FromSeconds(-1) (negative, not infinite); options.StopTimeout = TimeSpan.FromMilliseconds(int.MaxValue + 1.0) (over the limit); binding a config value parsed from a negative or huge number.","commonSituations":"Config typos (negative timeout); unit mismatches (treating a value as seconds but it is milliseconds, producing an overflow); binding TimeSpan.MaxValue from config; tests that probe boundary values.","solutions":["Use a non-negative TimeSpan within Int32.MaxValue milliseconds (about 24.8 days), or Timeout.InfiniteTimeSpan.","Clamp the bound value: options.StopTimeout = TimeSpan.FromMilliseconds(Math.Clamp(ms, 0, int.MaxValue)).","Use the default (BackgroundProcessingServerOptions.DefaultStopTimeout) by not setting the property.","Validate the configured timeout at startup."],"exampleFix":"// before\noptions.StopTimeout = TimeSpan.FromSeconds(-5);\n\n// after\noptions.StopTimeout = TimeSpan.FromSeconds(30); // or leave default","handlingStrategy":"validation","validationCode":"TimeSpan SanitizeTimeout(TimeSpan ts) =>\n    ts == Timeout.InfiniteTimeSpan || (ts >= TimeSpan.Zero && ts.TotalMilliseconds <= int.MaxValue)\n        ? ts : BackgroundProcessingServerOptions.DefaultStopTimeout;\noptions.StopTimeout = SanitizeTimeout(parsed);","typeGuard":"static bool IsValidTimeout(TimeSpan ts) => ts == Timeout.InfiniteTimeSpan || (ts >= TimeSpan.Zero && ts.TotalMilliseconds <= int.MaxValue);","tryCatchPattern":"try { options.StopTimeout = parsed; }\ncatch (ArgumentOutOfRangeException) { options.StopTimeout = BackgroundProcessingServerOptions.DefaultStopTimeout; }","preventionTips":["Clamp timeouts into [0, Int32.MaxValue] ms.","Use Timeout.InfiniteTimeSpan for \"forever\".","Validate config units (seconds vs milliseconds)."],"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-14T05:17:29.042Z"}