SignalR/SignalR · error · ArgumentOutOfRangeException

KeepAlive value must be greater than two seconds.

Error message

KeepAlive value must be greater than two seconds.

What it means

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.

Source

Thrown at src/Microsoft.AspNet.SignalR.Core/Configuration/DefaultConfigurationManager.cs:78

                    throw new InvalidOperationException(Resources.Error_DisconnectTimeoutCannotBeConfiguredAfterKeepAlive);
                }

                _disconnectTimeout = value;
                _keepAlive = TimeSpan.FromTicks(_disconnectTimeout.Ticks / _minimumKeepAlivesPerDisconnectTimeout);
            }
        }

        public TimeSpan? KeepAlive
        {
            get
            {
                return _keepAlive;
            }
            set
            {
                if (value < _minimumKeepAlive)
                {
                    throw new ArgumentOutOfRangeException("value", Resources.Error_KeepAliveMustBeGreaterThanTwoSeconds);
                }

                if (value > TimeSpan.FromTicks(_disconnectTimeout.Ticks / _minimumKeepAlivesPerDisconnectTimeout))
                {
                    throw new ArgumentOutOfRangeException("value", Resources.Error_KeepAliveMustBeNoMoreThanAThirdOfTheDisconnectTimeout);
                }

                _keepAlive = value;
                _keepAliveConfigured = true;
            }
        }

        public int DefaultMessageBufferSize
        {
            get;
            set;
        }

View on GitHub (pinned to 693053b89a)

Solutions

  1. Use a KeepAlive of at least two seconds (e.g., TimeSpan.FromSeconds(2) or higher).
  2. Ensure the value is also no more than a third of DisconnectTimeout.
  3. Leave KeepAlive at its default if tuning is unnecessary.

Example fix

// before
GlobalHost.Configuration.KeepAlive = TimeSpan.FromMilliseconds(500);

// after
GlobalHost.Configuration.KeepAlive = TimeSpan.FromSeconds(2);
Defensive patterns

Strategy: validation

Validate before calling

var desired = TimeSpan.FromSeconds(keepAliveSeconds);
if (desired >= TimeSpan.FromSeconds(2))
    GlobalHost.Configuration.KeepAlive = desired;

Type guard

static readonly TimeSpan MinimumKeepAlive = TimeSpan.FromSeconds(2);

Prevention

When it happens

Trigger: Setting GlobalHost.Configuration.KeepAlive to a TimeSpan less than two seconds.

Common situations: Tuning for very low latency or aggressive connection liveness detection; using a sub-two-second value copied from an outdated guide.

Related errors


AI-assisted analysis of SignalR/SignalR@693053b89a (2026-08-13). Data as JSON: /api/errors/9164a76c57404405. Report an issue: GitHub.