{"record":{"id":"9164a76c57404405","repo":"SignalR/SignalR","slug":"keepalive-value-must-be-greater-than-two-seconds","errorCode":null,"errorMessage":"KeepAlive value must be greater than two seconds.","messagePattern":"KeepAlive value must be greater than two seconds\\.","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.AspNet.SignalR.Core/Configuration/DefaultConfigurationManager.cs","lineNumber":78,"sourceCode":"                    throw new InvalidOperationException(Resources.Error_DisconnectTimeoutCannotBeConfiguredAfterKeepAlive);\n                }\n\n                _disconnectTimeout = value;\n                _keepAlive = TimeSpan.FromTicks(_disconnectTimeout.Ticks / _minimumKeepAlivesPerDisconnectTimeout);\n            }\n        }\n\n        public TimeSpan? KeepAlive\n        {\n            get\n            {\n                return _keepAlive;\n            }\n            set\n            {\n                if (value < _minimumKeepAlive)\n                {\n                    throw new ArgumentOutOfRangeException(\"value\", Resources.Error_KeepAliveMustBeGreaterThanTwoSeconds);\n                }\n\n                if (value > TimeSpan.FromTicks(_disconnectTimeout.Ticks / _minimumKeepAlivesPerDisconnectTimeout))\n                {\n                    throw new ArgumentOutOfRangeException(\"value\", Resources.Error_KeepAliveMustBeNoMoreThanAThirdOfTheDisconnectTimeout);\n                }\n\n                _keepAlive = value;\n                _keepAliveConfigured = true;\n            }\n        }\n\n        public int DefaultMessageBufferSize\n        {\n            get;\n            set;\n        }\n","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/SignalR/SignalR/blob/693053b89a9e1f5ce819e3233ed159a6409de22b/src/Microsoft.AspNet.SignalR.Core/Configuration/DefaultConfigurationManager.cs#L60-L96","documentation":"Thrown by DefaultConfigurationManager.KeepAlive setter when the supplied value is below _minimumKeepAlive (two seconds). KeepAlive controls how often the server sends keep-alive pings; a value too small would flood clients with pings, so it is clamped to a safe floor.","triggerScenarios":"Setting GlobalHost.Configuration.KeepAlive to a TimeSpan less than two seconds.","commonSituations":"Tuning for very low latency or aggressive connection liveness detection; using a sub-two-second value copied from an outdated guide.","solutions":["Use a KeepAlive of at least two seconds (e.g., TimeSpan.FromSeconds(2) or higher).","Ensure the value is also no more than a third of DisconnectTimeout.","Leave KeepAlive at its default if tuning is unnecessary."],"exampleFix":"// before\nGlobalHost.Configuration.KeepAlive = TimeSpan.FromMilliseconds(500);\n\n// after\nGlobalHost.Configuration.KeepAlive = TimeSpan.FromSeconds(2);","handlingStrategy":"validation","validationCode":"var desired = TimeSpan.FromSeconds(keepAliveSeconds);\nif (desired >= TimeSpan.FromSeconds(2))\n    GlobalHost.Configuration.KeepAlive = desired;","typeGuard":"static readonly TimeSpan MinimumKeepAlive = TimeSpan.FromSeconds(2);","tryCatchPattern":null,"preventionTips":["Keep KeepAlive >= 2 seconds.","Validate loaded config values against the floor before applying.","Prefer the default unless tuning is truly needed."],"tags":["argumentoutofrange","configuration","timeout","keepalive","server"],"backgroundTag":null,"analyzedSha":"693053b89a9e1f5ce819e3233ed159a6409de22b","analyzedAt":"2026-08-13T22:23:59.793Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}