Skip to content

Commit e5d42d9

Browse files
committed
Move TryGetConnectionCompletedContinuation
1 parent 396bab5 commit e5d42d9

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionFactory.cs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -47,39 +47,6 @@ protected static Task<DbConnectionInternal> GetCompletedTask()
4747
return s_completedTask ?? (s_completedTask = Task.FromResult<DbConnectionInternal>(null));
4848
}
4949

50-
protected void TryGetConnectionCompletedContinuation(Task<DbConnectionInternal> task, object state)
51-
{
52-
Tuple<CancellationTokenSource, TaskCompletionSource<DbConnectionInternal>> parameters = (Tuple<CancellationTokenSource, TaskCompletionSource<DbConnectionInternal>>)state;
53-
CancellationTokenSource source = parameters.Item1;
54-
source.Dispose();
55-
56-
TaskCompletionSource<DbConnectionInternal> retryCompletionSource = parameters.Item2;
57-
58-
if (task.IsCanceled)
59-
{
60-
retryCompletionSource.TrySetException(ADP.ExceptionWithStackTrace(ADP.NonPooledOpenTimeout()));
61-
}
62-
else if (task.IsFaulted)
63-
{
64-
retryCompletionSource.TrySetException(task.Exception.InnerException);
65-
}
66-
else
67-
{
68-
if (!retryCompletionSource.TrySetResult(task.Result))
69-
{
70-
// The outer TaskCompletionSource was already completed
71-
// Which means that we don't know if someone has messed with the outer connection in the middle of creation
72-
// So the best thing to do now is to destroy the newly created connection
73-
task.Result.DoomThisConnection();
74-
task.Result.Dispose();
75-
}
76-
else
77-
{
78-
SqlClientEventSource.Metrics.EnterNonPooledConnection();
79-
}
80-
}
81-
}
82-
8350
protected IDbConnectionPool GetConnectionPool(DbConnection owningObject, DbConnectionPoolGroup connectionPoolGroup)
8451
{
8552
// if poolgroup is disabled, it will be replaced with a new entry

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,39 @@ private Task<DbConnectionInternal> CreateReplaceConnectionContinuation(
668668
TaskScheduler.Default
669669
);
670670
}
671+
672+
private void TryGetConnectionCompletedContinuation(Task<DbConnectionInternal> task, object state)
673+
{
674+
// Decompose the state into the parameters we want
675+
(CancellationTokenSource cts, TaskCompletionSource<DbConnectionInternal> tcs) =
676+
(Tuple<CancellationTokenSource, TaskCompletionSource<DbConnectionInternal>>)state;
677+
678+
cts.Dispose();
679+
680+
if (task.IsCanceled)
681+
{
682+
tcs.TrySetException(ADP.ExceptionWithStackTrace(ADP.NonPooledOpenTimeout()));
683+
}
684+
else if (task.IsFaulted)
685+
{
686+
tcs.TrySetException(task.Exception.InnerException);
687+
}
688+
else
689+
{
690+
if (!tcs.TrySetResult(task.Result))
691+
{
692+
// The outer TaskCompletionSource was already completed
693+
// Which means that we don't know if someone has messed with the outer connection in the middle of creation
694+
// So the best thing to do now is to destroy the newly created connection
695+
task.Result.DoomThisConnection();
696+
task.Result.Dispose();
697+
}
698+
else
699+
{
700+
SqlClientEventSource.Metrics.EnterNonPooledConnection();
701+
}
702+
}
703+
}
671704

672705
#if NET
673706
private void Unload(object sender, EventArgs e)

0 commit comments

Comments
 (0)