Skip to content

Commit 09bc6fd

Browse files
committed
netfx: port dotnet#378
1 parent b6315e4 commit 09bc6fd

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ private static readonly ConcurrentDictionary<string, IList<string>> _ColumnEncry
119119
capacity: 1,
120120
comparer: StringComparer.OrdinalIgnoreCase);
121121

122+
private static readonly Action<object> s_openAsyncCancel = OpenAsyncCancel;
122123
private static readonly Action<Task<object>, object> s_openAsyncComplete = OpenAsyncComplete;
123124

124125
private bool IsProviderRetriable => SqlConfigurableRetryFactory.IsRetriable(RetryLogicProvider);
@@ -1768,7 +1769,7 @@ private Task InternalOpenAsync(SqlConnectionOverrides overrides, CancellationTok
17681769
CancellationTokenRegistration registration = new CancellationTokenRegistration();
17691770
if (cancellationToken.CanBeCanceled)
17701771
{
1771-
registration = cancellationToken.Register(() => completion.TrySetCanceled());
1772+
registration = cancellationToken.Register(s_openAsyncCancel, completion);
17721773
}
17731774
OpenAsyncRetry retry = new OpenAsyncRetry(this, completion, result, overrides, registration);
17741775
_currentCompletion = new Tuple<TaskCompletionSource<DbConnectionInternal>, Task>(completion, result.Task);
@@ -1810,6 +1811,11 @@ private static void OpenAsyncComplete(Task<object> task, object state)
18101811
}
18111812
}
18121813

1814+
private static void OpenAsyncCancel(object state)
1815+
{
1816+
((TaskCompletionSource<DbConnectionInternal>)state).TrySetCanceled();
1817+
}
1818+
18131819
private class OpenAsyncRetry
18141820
{
18151821
private SqlConnection _parent;

0 commit comments

Comments
 (0)