Skip to content

Commit fbda636

Browse files
committed
fix(CanConnectAsync): throw OperationCanceledException in case of cancellation
1 parent 7a87abf commit fbda636

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/EFCore.Relational/Storage/RelationalDatabaseCreator.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,10 @@ public virtual async Task<bool> CanConnectAsync(CancellationToken cancellationTo
393393
{
394394
return await ExistsAsync(cancellationToken).ConfigureAwait(false);
395395
}
396+
catch (Exception exception) when (Dependencies.ExceptionDetector.IsCancellation(exception, cancellationToken))
397+
{
398+
throw new OperationCanceledException(null, exception, cancellationToken);
399+
}
396400
catch
397401
{
398402
return false;

src/EFCore.Relational/Storage/RelationalDatabaseCreatorDependencies.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public RelationalDatabaseCreatorDependencies(
5454
IExecutionStrategy executionStrategy,
5555
ICurrentDbContext currentContext,
5656
IDbContextOptions contextOptions,
57-
IRelationalCommandDiagnosticsLogger commandLogger)
57+
IRelationalCommandDiagnosticsLogger commandLogger,
58+
IExceptionDetector exceptionDetector)
5859
{
5960
Connection = connection;
6061
ModelDiffer = modelDiffer;
@@ -65,6 +66,7 @@ public RelationalDatabaseCreatorDependencies(
6566
CurrentContext = currentContext;
6667
ContextOptions = contextOptions;
6768
CommandLogger = commandLogger;
69+
ExceptionDetector = exceptionDetector;
6870
}
6971

7072
/// <summary>
@@ -111,4 +113,9 @@ public RelationalDatabaseCreatorDependencies(
111113
/// Contains the <see cref="DbContext" /> currently in use.
112114
/// </summary>
113115
public ICurrentDbContext CurrentContext { get; init; }
116+
117+
/// <summary>
118+
/// Gets the exception detector.
119+
/// </summary>
120+
public IExceptionDetector ExceptionDetector { get; init; }
114121
}

0 commit comments

Comments
 (0)