Skip to content

Commit 9041a52

Browse files
authored
Remove CER (#3535)
* Remove CER from sqlbulkcopy * Remove CER from SqlDataReader * Remove CER from SqlDependency? * Remove CER From WaitHandleDbConnectionPool * Remove CER from SqlTransaction * Remove CER from SqlUtil * Remove CER from SniNativeWrapper * Remove CER from netcore SqlCommand * Remove CER from SqlConnection (netcore) and SqlCommandBuilder * Remove CER from SqlDelegatedTransaction * Remove CER from SqlInternalConnection * Remove CER from SqlInternalConnectionTds * Remove CER from TdsParser (netcore) * Remove CER from TdsParserStateObject (netcore) * Remove CER from TdsParserStateObjectNative and LocalDbApi * Remove CER from SqlCommand * Remove CER from SqlConnection * Remove CER from SqlInternalConnectionTds.cs and SqlDependencyListener.cs * Cleanup the rest of CER * Removing the last batches of CER exception stuff * Add comments that indicate where CER exception handling was removed
1 parent dc8f23b commit 9041a52

34 files changed

+969
-2685
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,18 +1411,7 @@ private void BeginExecuteNonQueryInternalReadStage(TaskCompletionSource<object>
14111411
CachedAsyncState.SetActiveConnectionAndResult(completion, nameof(EndExecuteNonQuery), _activeConnection);
14121412
_stateObj.ReadSni(completion);
14131413
}
1414-
// Cause of a possible unstable runtime situation on facing with `OutOfMemoryException` and `StackOverflowException` exceptions,
1415-
// trying to call further functions in the catch of either may fail that should be considered on debuging!
1416-
catch (System.OutOfMemoryException e)
1417-
{
1418-
_activeConnection.Abort(e);
1419-
throw;
1420-
}
1421-
catch (System.StackOverflowException e)
1422-
{
1423-
_activeConnection.Abort(e);
1424-
throw;
1425-
}
1414+
// @TODO: CER Exception Handling was removed here (see GH#3581)
14261415
catch (Exception)
14271416
{
14281417
// Similarly, if an exception occurs put the stateObj back into the pool.
@@ -1968,20 +1957,7 @@ private void BeginExecuteXmlReaderInternalReadStage(TaskCompletionSource<object>
19681957
CachedAsyncState.SetActiveConnectionAndResult(completion, nameof(EndExecuteXmlReader), _activeConnection);
19691958
_stateObj.ReadSni(completion);
19701959
}
1971-
// Cause of a possible unstable runtime situation on facing with `OutOfMemoryException` and `StackOverflowException` exceptions,
1972-
// trying to call further functions in the catch of either may fail that should be considered on debuging!
1973-
catch (System.OutOfMemoryException e)
1974-
{
1975-
_activeConnection.Abort(e);
1976-
completion.TrySetException(e);
1977-
throw;
1978-
}
1979-
catch (System.StackOverflowException e)
1980-
{
1981-
_activeConnection.Abort(e);
1982-
completion.TrySetException(e);
1983-
throw;
1984-
}
1960+
// @TODO: CER Exception Handling was removed here (see GH#3581)
19851961
catch (Exception e)
19861962
{
19871963
// Similarly, if an exception occurs put the stateObj back into the pool.
@@ -2633,20 +2609,7 @@ private void BeginExecuteReaderInternalReadStage(TaskCompletionSource<object> co
26332609
CachedAsyncState.SetActiveConnectionAndResult(completion, nameof(EndExecuteReader), _activeConnection);
26342610
_stateObj.ReadSni(completion);
26352611
}
2636-
// Cause of a possible unstable runtime situation on facing with `OutOfMemoryException` and `StackOverflowException` exceptions,
2637-
// trying to call further functions in the catch of either may fail that should be considered on debuging!
2638-
catch (System.OutOfMemoryException e)
2639-
{
2640-
_activeConnection.Abort(e);
2641-
completion.TrySetException(e);
2642-
throw;
2643-
}
2644-
catch (System.StackOverflowException e)
2645-
{
2646-
_activeConnection.Abort(e);
2647-
completion.TrySetException(e);
2648-
throw;
2649-
}
2612+
// @TODO: CER Exception Handling was removed here (see GH#3581)
26502613
catch (Exception e)
26512614
{
26522615
// Similarly, if an exception occurs put the stateObj back into the pool.
@@ -4114,9 +4077,7 @@ private SqlDataReader GetParameterEncryptionDataReader(out Task returnTask, Task
41144077
SqlCommand command = (SqlCommand)state;
41154078
bool processFinallyBlockAsync = true;
41164079
bool decrementAsyncCountInFinallyBlockAsync = true;
4117-
#if NETFRAMEWORK
4118-
RuntimeHelpers.PrepareConstrainedRegions();
4119-
#endif
4080+
41204081
try
41214082
{
41224083
// Check for any exceptions on network write, before reading.
@@ -4187,10 +4148,7 @@ private SqlDataReader GetParameterEncryptionDataReaderAsync(out Task returnTask,
41874148
{
41884149
bool processFinallyBlockAsync = true;
41894150
bool decrementAsyncCountInFinallyBlockAsync = true;
4190-
4191-
#if NETFRAMEWORK
4192-
RuntimeHelpers.PrepareConstrainedRegions();
4193-
#endif
4151+
41944152
try
41954153
{
41964154
// Check for any exceptions on network write, before reading.

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

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,35 +1237,13 @@ public override void ChangeDatabase(string database)
12371237
SqlStatistics statistics = null;
12381238
RepairInnerConnection();
12391239
SqlClientEventSource.Log.TryCorrelationTraceEvent("SqlConnection.ChangeDatabase | API | Correlation | Object Id {0}, Activity Id {1}, Database {2}", ObjectID, ActivityCorrelator.Current, database);
1240-
TdsParser bestEffortCleanupTarget = null;
1241-
1242-
#if NETFRAMEWORK
1243-
RuntimeHelpers.PrepareConstrainedRegions();
1244-
#endif
1240+
12451241
try
12461242
{
1247-
bestEffortCleanupTarget = SqlInternalConnection.GetBestEffortCleanupTarget(this);
12481243
statistics = SqlStatistics.StartTimer(Statistics);
12491244
InnerConnection.ChangeDatabase(database);
12501245
}
1251-
catch (System.OutOfMemoryException e)
1252-
{
1253-
Abort(e);
1254-
throw;
1255-
}
1256-
catch (System.StackOverflowException e)
1257-
{
1258-
Abort(e);
1259-
throw;
1260-
}
1261-
catch (System.Threading.ThreadAbortException e)
1262-
{
1263-
Abort(e);
1264-
#if NETFRAMEWORK
1265-
SqlInternalConnection.BestEffortCleanup(bestEffortCleanupTarget);
1266-
#endif
1267-
throw;
1268-
}
1246+
// @TODO: CER Exception Handling was removed here (see GH#3581)
12691247
finally
12701248
{
12711249
SqlStatistics.StopTimer(statistics);
@@ -1328,15 +1306,10 @@ public override void Close()
13281306
}
13291307

13301308
SqlStatistics statistics = null;
1331-
TdsParser bestEffortCleanupTarget = null;
13321309
Exception e = null;
1333-
1334-
#if NETFRAMEWORK
1335-
RuntimeHelpers.PrepareConstrainedRegions();
1336-
#endif
1310+
13371311
try
13381312
{
1339-
bestEffortCleanupTarget = SqlInternalConnection.GetBestEffortCleanupTarget(this);
13401313
statistics = SqlStatistics.StartTimer(Statistics);
13411314

13421315
Task reconnectTask = _currentReconnectionTask;
@@ -1362,27 +1335,7 @@ public override void Close()
13621335
_statistics._closeTimestamp = ADP.TimerCurrent();
13631336
}
13641337
}
1365-
catch (System.OutOfMemoryException ex)
1366-
{
1367-
e = ex;
1368-
Abort(ex);
1369-
throw;
1370-
}
1371-
catch (System.StackOverflowException ex)
1372-
{
1373-
e = ex;
1374-
Abort(ex);
1375-
throw;
1376-
}
1377-
catch (System.Threading.ThreadAbortException ex)
1378-
{
1379-
e = ex;
1380-
Abort(ex);
1381-
#if NETFRAMEWORK
1382-
SqlInternalConnection.BestEffortCleanup(bestEffortCleanupTarget);
1383-
#endif
1384-
throw;
1385-
}
1338+
// @TODO: CER Exception Handling was removed here (see GH#3581)
13861339
catch (Exception ex)
13871340
{
13881341
e = ex;

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs

Lines changed: 11 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,6 @@ internal SqlInternalConnectionTds(
539539
_parserLock.Wait(canReleaseFromAnyThread: false);
540540
ThreadHasParserLockForClose = true; // In case of error, let ourselves know that we already own the parser lock
541541

542-
#if NETFRAMEWORK
543-
RuntimeHelpers.PrepareConstrainedRegions();
544-
#endif
545542
try
546543
{
547544
_timeout = TimeoutTimer.StartSecondsTimeout(connectionOptions.ConnectTimeout);
@@ -573,21 +570,7 @@ internal SqlInternalConnectionTds(
573570
}
574571
}
575572
}
576-
catch (System.OutOfMemoryException)
577-
{
578-
DoomThisConnection();
579-
throw;
580-
}
581-
catch (System.StackOverflowException)
582-
{
583-
DoomThisConnection();
584-
throw;
585-
}
586-
catch (System.Threading.ThreadAbortException)
587-
{
588-
DoomThisConnection();
589-
throw;
590-
}
573+
// @TODO: CER Exception Handling was removed here (see GH#3581)
591574
finally
592575
{
593576
ThreadHasParserLockForClose = false;
@@ -2136,39 +2119,19 @@ internal bool GetSessionAndReconnectIfNeeded(SqlConnection parent, int timeout =
21362119

21372120
try
21382121
{
2139-
#if NETFRAMEWORK
2140-
RuntimeHelpers.PrepareConstrainedRegions();
2141-
#endif
2142-
try
2122+
Task reconnectTask = parent.ValidateAndReconnect(() =>
21432123
{
2144-
Task reconnectTask = parent.ValidateAndReconnect(() =>
2145-
{
2146-
ThreadHasParserLockForClose = false;
2147-
_parserLock.Release();
2148-
releaseConnectionLock = false;
2149-
}, timeout);
2150-
if (reconnectTask != null)
2151-
{
2152-
AsyncHelper.WaitForCompletion(reconnectTask, timeout);
2153-
return true;
2154-
}
2155-
return false;
2156-
}
2157-
catch (System.OutOfMemoryException)
2158-
{
2159-
DoomThisConnection();
2160-
throw;
2161-
}
2162-
catch (System.StackOverflowException)
2163-
{
2164-
DoomThisConnection();
2165-
throw;
2166-
}
2167-
catch (System.Threading.ThreadAbortException)
2124+
ThreadHasParserLockForClose = false;
2125+
_parserLock.Release();
2126+
releaseConnectionLock = false;
2127+
}, timeout);
2128+
if (reconnectTask != null)
21682129
{
2169-
DoomThisConnection();
2170-
throw;
2130+
AsyncHelper.WaitForCompletion(reconnectTask, timeout);
2131+
return true;
21712132
}
2133+
return false;
2134+
// @TODO: CER Exception Handling was removed here (see GH#3581)
21722135
}
21732136
finally
21742137
{
@@ -2475,10 +2438,6 @@ internal bool TryGetFedAuthTokenLocked(SqlFedAuthInfo fedAuthInfo, DbConnectionP
24752438
// Variable which indicates if we did indeed manage to acquire the lock on the authentication context, to try update it.
24762439
bool authenticationContextLocked = false;
24772440

2478-
// Prepare CER to ensure the lock on authentication context is released.
2479-
#if NETFRAMEWORK
2480-
RuntimeHelpers.PrepareConstrainedRegions();
2481-
#endif
24822441
try
24832442
{
24842443
// Try to obtain a lock on the context. If acquired, this thread got the opportunity to update.

0 commit comments

Comments
 (0)