Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TimeoutStrategyOptions.TimeoutGenerator docs are incorrect #2266

Closed
wjrogers opened this issue Aug 13, 2024 · 3 comments
Closed

TimeoutStrategyOptions.TimeoutGenerator docs are incorrect #2266

wjrogers opened this issue Aug 13, 2024 · 3 comments

Comments

@wjrogers
Copy link

The XML comment on the TimeoutGenerator property says that returning TimeSpan.Zero means "use Timeout instead":

/// If generator returns a <see cref="TimeSpan"/> value that is less or equal to <see cref="TimeSpan.Zero"/>
/// its value is ignored and <see cref="Timeout"/> is used instead. When generator is <see langword="null"/> the <see cref="Timeout"/> is used.

However, the code has no such logic. Any return value less than or equal to TimeSpan.Zero is treated as an infinite timeout:

if (TimeoutGenerator is not null)
{
timeout = await TimeoutGenerator!(new TimeoutGeneratorArguments(context)).ConfigureAwait(context.ContinueOnCapturedContext);
}
if (!TimeoutUtil.ShouldApplyTimeout(timeout))
{
// do nothing
return await callback(context, state).ConfigureAwait(context.ContinueOnCapturedContext);
}

@peter-csala
Copy link
Contributor

peter-csala commented Aug 14, 2024

In case of Retry when the DelayGenerator returns null or zero or negative timestamp then it falls back to the Delay property based calculation.

var delay = RetryHelper.GetRetryDelay(BackoffType, UseJitter, attempt, BaseDelay, MaxDelay, ref retryState, _randomizer);
if (DelayGenerator is not null)
{
var delayArgs = new RetryDelayGeneratorArguments<T>(context, outcome, attempt);
if (await DelayGenerator(delayArgs).ConfigureAwait(false) is TimeSpan newDelay && RetryHelper.IsValidDelay(newDelay))
{
delay = newDelay;
}
}

public static bool IsValidDelay(TimeSpan delay) => delay >= TimeSpan.Zero;

I assume we wanted to have something similar for the TimeoutStrategy.


BUT now it behaves in the following way:

  • If only Timeout is defined then that is used
  • If only TimeoutGenerator is defined then that is used
  • If both Timeout and TimeoutGenerator are defined then Timeout is ignored.

@peter-csala
Copy link
Contributor

@martincostello Can you close this issue please?

@martincostello
Copy link
Member

Resolved by #2275.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants