Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Dont allow exceptions to emerge on the threadpool #27439

Merged
merged 3 commits into from
Feb 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1376,9 +1376,19 @@ private void PoolCreateRequest(object state)
{
while (NeedToReplenish)
{
// Don't specify any user options because there is no outer connection associated with the new connection
newObj = CreateObject(owningObject: null, userOptions: null, oldConnection: null);

try
{
// Don't specify any user options because there is no outer connection associated with the new connection
newObj = CreateObject(owningObject: null, userOptions: null, oldConnection: null);
}
catch
{
// Catch all the exceptions occuring during CreateObject so that they
// don't emerge as unhandled on the thread pool and don't crash applications
// The error is handled in CreateObject and surfaced to the caller of the Connection Pool
// using the ErrorEvent. Hence it is OK to swallow all exceptions here.
break;
}
// We do not need to check error flag here, since we know if
// CreateObject returned null, we are in error case.
if (null != newObj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,21 @@ public void ConnectionTimeoutTestWithThread()
Console.WriteLine($"ConnectionTimeoutTestWithThread: Elapsed Time {theMax} and threshold {threshold}");
}

[OuterLoop("Can take up to 4 seconds")]
[Fact]
public void ExceptionsWithMinPoolSizeCanBeHandled()
{
string connectionString = $"Data Source={Guid.NewGuid().ToString()};uid=random;pwd=asd;Connect Timeout=2; Min Pool Size=3";
for (int i = 0; i < 2; i++)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
Exception exception = Record.Exception(() => connection.Open());
Assert.True(exception is InvalidOperationException || exception is SqlException, $"Unexpected exception: {exception}");
}
}
}

public class ConnectionWorker
{
private static ManualResetEventSlim startEvent = new ManualResetEventSlim(false);
Expand Down