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

Fix infinite recursive generics #24211

Merged
merged 1 commit into from
Feb 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions src/EFCore/Storage/ExecutionStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,15 @@ public virtual bool RetriesOnFailure

OnFirstExecution();

return ExecuteImplementation(operation, verifySucceeded, state);
// In order to avoid infinite recursive generics, wrap operation with ExecutionResult
return ExecuteImplementation(
(context, state) => new ExecutionResult<TResult>(true, operation(context, state)),
verifySucceeded,
state).Result;
}

private TResult ExecuteImplementation<TState, TResult>(
Func<DbContext, TState, TResult> operation,
private ExecutionResult<TResult> ExecuteImplementation<TState, TResult>(
Func<DbContext, TState, ExecutionResult<TResult>> operation,
Func<DbContext, TState, ExecutionResult<TResult>>? verifySucceeded,
TState state)
{
Expand All @@ -188,7 +192,7 @@ public virtual bool RetriesOnFailure
var result = ExecuteImplementation(verifySucceeded, null, state);
if (result.IsSuccessful)
{
return result.Result;
return result;
}
}

Expand Down Expand Up @@ -238,7 +242,7 @@ public virtual bool RetriesOnFailure
/// The operation has not succeeded after the configured number of retries.
/// </exception>
/// <exception cref="OperationCanceledException"> If the <see cref="CancellationToken"/> is canceled. </exception>
public virtual Task<TResult> ExecuteAsync<TState, TResult>(
public virtual async Task<TResult> ExecuteAsync<TState, TResult>(
TState state,
Func<DbContext, TState, CancellationToken, Task<TResult>> operation,
Func<DbContext, TState, CancellationToken, Task<ExecutionResult<TResult>>>? verifySucceeded,
Expand All @@ -248,15 +252,22 @@ public virtual bool RetriesOnFailure

if (Suspended)
{
return operation(Dependencies.CurrentContext.Context, state, cancellationToken);
return await operation(Dependencies.CurrentContext.Context, state, cancellationToken).ConfigureAwait(false);
}

OnFirstExecution();
return ExecuteImplementationAsync(operation, verifySucceeded, state, cancellationToken);

// In order to avoid infinite recursive generics, wrap operation with ExecutionResult
var result = await ExecuteImplementationAsync(
async (context, state, cancellationToken) => new ExecutionResult<TResult>(true, await operation(context, state, cancellationToken).ConfigureAwait(false)),
verifySucceeded,
state,
cancellationToken).ConfigureAwait(false);
return result.Result;
}

private async Task<TResult> ExecuteImplementationAsync<TState, TResult>(
Func<DbContext, TState, CancellationToken, Task<TResult>> operation,
private async Task<ExecutionResult<TResult>> ExecuteImplementationAsync<TState, TResult>(
Func<DbContext, TState, CancellationToken, Task<ExecutionResult<TResult>>> operation,
Func<DbContext, TState, CancellationToken, Task<ExecutionResult<TResult>>>? verifySucceeded,
TState state,
CancellationToken cancellationToken)
Expand Down Expand Up @@ -286,7 +297,7 @@ public virtual bool RetriesOnFailure
.ConfigureAwait(false);
if (result.IsSuccessful)
{
return result.Result;
return result;
}
}

Expand Down