TechnitiumSoftware/DnsServer · error · ArgumentOutOfRangeException

Serve stale max wait time valid range is 0 to 1800 milliseco

Error message

Serve stale max wait time valid range is 0 to 1800 milliseconds. Default value is 1800 milliseconds.

What it means

Thrown by the ServeStaleMaxWaitTime property setter when the value is outside [0, 1800] milliseconds. This controls how long the server waits (when ServeStale is enabled) for a refreshed answer before falling back to serving an expired cached record, with 1800ms being the default maximum.

Source

Thrown at DnsServerCore/Dns/DnsServer.cs:7996

                        _log.Write(ex);
                    }
                }
            }
        }

        public bool ServeStale
        {
            get { return _serveStale; }
            set { _serveStale = value; }
        }

        public int ServeStaleMaxWaitTime
        {
            get { return _serveStaleMaxWaitTime; }
            set
            {
                if ((value < 0) || (value > 1800))
                    throw new ArgumentOutOfRangeException(nameof(ServeStaleMaxWaitTime), "Serve stale max wait time valid range is 0 to 1800 milliseconds. Default value is 1800 milliseconds.");

                _serveStaleMaxWaitTime = value;
            }
        }

        public int CachePrefetchEligibility
        {
            get { return _cachePrefetchEligibility; }
            set
            {
                if (value < 2)
                    throw new ArgumentOutOfRangeException(nameof(CachePrefetchEligibility), "Valid value is greater that or equal to 2.");

                _cachePrefetchEligibility = value;
            }
        }

        public int CachePrefetchTrigger

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Supply a millisecond value in 0–1800 (0 means serve stale immediately without waiting).
  2. If your config is in seconds, convert to milliseconds before assigning.
  3. Keep ServeStale = true only when you actually want stale fallback behavior.

Example fix

// before
server.ServeStaleMaxWaitTime = 2; // meant 2s; 2ms is fine but likely unintended

// after
server.ServeStaleMaxWaitTime = 1800; // default max wait
Defensive patterns

Strategy: validation

Validate before calling

// config in seconds -> ms, clamped to 0–1800
static int ToStaleWaitMs(int seconds) => Math.Clamp(seconds * 1000, 0, 1800);
server.ServeStaleMaxWaitTime = ToStaleWaitMs(configSeconds);

Type guard

static bool IsValidStaleWait(int ms) => ms >= 0 && ms <= 1800;

Try / catch

try { server.ServeStaleMaxWaitTime = ms; }
catch (ArgumentOutOfRangeException) { server.ServeStaleMaxWaitTime = 1800; }

Prevention

When it happens

Trigger: Setting DnsServer.ServeStaleMaxWaitTime to a negative value or a value greater than 1800 (milliseconds).

Common situations: Assuming seconds instead of milliseconds; setting a large value to always prefer fresh answers; setting negative to disable.

Related errors


AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13). Data as JSON: /api/errors/3f2505446b42d6e0. Report an issue: GitHub.