App-vNext/Polly · error · ArgumentNullException
timeoutProvider
Error message
timeoutProvider
What it means
ArgumentNullException (ParamName "timeoutProvider") is thrown at configuration time by TimeoutAsync(Func<TimeSpan> timeoutProvider) when the provider is null (AsyncTimeoutSyntax.cs:200-203). The provider is mandatory because the timeout is resolved per-execution; without it the policy cannot compute a deadline. This overload wraps the provider in a Context-ignoring lambda and uses the optimistic strategy with an empty timeout handler.
Source
Thrown at src/Polly/Timeout/AsyncTimeoutSyntax.cs:202
/// <exception cref="ArgumentNullException">Thrown when <paramref name="onTimeoutAsync"/> is <see langword="null"/>.</exception>
public static AsyncTimeoutPolicy TimeoutAsync(TimeSpan timeout, TimeoutStrategy timeoutStrategy, Func<Context, TimeSpan, Task, Exception, Task> onTimeoutAsync)
{
TimeoutValidator.ValidateTimeSpanTimeout(timeout);
return TimeoutAsync(_ => timeout, timeoutStrategy, onTimeoutAsync);
}
/// <summary>
/// Builds an <see cref="AsyncPolicy"/> that will wait asynchronously for a delegate to complete for a specified period of time. A <see cref="TimeoutRejectedException"/> will be thrown if the delegate does not complete within the configured timeout.
/// </summary>
/// <param name="timeoutProvider">A function to provide the timeout for this execution.</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="timeoutProvider"/> is <see langword="null"/>.</exception>
/// <returns>The policy instance.</returns>
public static AsyncTimeoutPolicy TimeoutAsync(Func<TimeSpan> timeoutProvider)
{
if (timeoutProvider == null)
{
throw new ArgumentNullException(nameof(timeoutProvider));
}
return TimeoutAsync(_ => timeoutProvider(), TimeoutStrategy.Optimistic, EmptyHandlerAsync);
}
/// <summary>
/// Builds an <see cref="AsyncPolicy" /> that will wait asynchronously for a delegate to complete for a specified period of time. A <see cref="TimeoutRejectedException" /> will be thrown if the delegate does not complete within the configured timeout.
/// </summary>
/// <param name="timeoutProvider">A function to provide the timeout for this execution.</param>
/// <param name="timeoutStrategy">The timeout strategy.</param>
/// <returns>The policy instance.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="timeoutProvider"/> is <see langword="null"/>.</exception>
public static AsyncTimeoutPolicy TimeoutAsync(Func<TimeSpan> timeoutProvider, TimeoutStrategy timeoutStrategy)
{
if (timeoutProvider == null)
{
throw new ArgumentNullException(nameof(timeoutProvider));
}View on GitHub (pinned to d0e46bdb1e)
Solutions
- Pass a non-null Func<TimeSpan>, e.g. () => TimeSpan.FromSeconds(30).
- If a fixed timeout suffices, use the TimeoutAsync(TimeSpan) or TimeoutAsync(int seconds) overload instead.
- Guard the provider in the composition root before building the policy.
Example fix
// before
Func<TimeSpan> provider = config.GetTimeoutProvider(); // null when missing
var policy = Policy.TimeoutAsync(provider);
// after
Func<TimeSpan> provider = config.GetTimeoutProvider()
?? (() => TimeSpan.FromSeconds(30));
var policy = Policy.TimeoutAsync(provider); Defensive patterns
Strategy: validation
Validate before calling
if (timeoutProvider is null) throw new InvalidOperationException("timeoutProvider is required.");
var policy = Policy.TimeoutAsync(timeoutProvider); Type guard
static bool IsValidTimeoutProvider(Func<TimeSpan> provider) => provider is not null;
Prevention
- Prefer the TimeoutAsync(TimeSpan) overload when the timeout is fixed; it removes the nullable provider.
- Coalesce null providers with a default function in the composition root.
- Source timeout providers from a single factory so they are never null.
When it happens
Trigger: Policy.TimeoutAsync((Func<TimeSpan>)null) — null passed as the timeout provider.
Common situations: Config-driven timeout function that resolved to null; refactor that extracted the provider into a field left null; tests stubbing only part of the call.
Understand the failure class
- Timeouts: ETIMEDOUT, deadlines, and hung requests — what actually expires when a request times out.
Related errors
- action
- seconds
- onRetry
- sleepDurationProvider
- No predicates were configured. There must be at least one pr
AI-assisted analysis of App-vNext/Polly@d0e46bdb1e (2026-08-13).
Data as JSON: /api/errors/325f76eb375345fb.
Report an issue: GitHub.