Skip to content

Commit

Permalink
Fix | Add thread safety with transient error list on configurable ret…
Browse files Browse the repository at this point in the history
…ry logic (#1911)

[3.1.2] Backport: Fix | Add thread safety with transient error list on configurable retry logic(#1911)
  • Loading branch information
Kaur-Parminder authored Jan 31, 2023
1 parent 4d8f8d1 commit 7f078be
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public sealed class SqlRetryLogicOption
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConfigurableRetryFactory.xml' path='docs/members[@name="SqlConfigurableRetryFactory"]/SqlConfigurableRetryFactory/*' />
public sealed class SqlConfigurableRetryFactory
{
private readonly static object s_syncObject = new();
/// Default known transient error numbers.
private static readonly HashSet<int> s_defaultTransientErrors
= new HashSet<int>
Expand Down Expand Up @@ -111,7 +112,12 @@ private static bool TransientErrorsCondition(Exception e, IEnumerable<int> retri
{
foreach (SqlError item in ex.Errors)
{
if (retriableConditions.Contains(item.Number))
bool retriable;
lock (s_syncObject)
{
retriable = retriableConditions.Contains(item.Number);
}
if (retriable)
{
SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|ERR|CATCH> Found a transient error: number = <{2}>, message = <{3}>", nameof(SqlConfigurableRetryFactory), MethodBase.GetCurrentMethod().Name, item.Number, item.Message);
result = true;
Expand Down

0 comments on commit 7f078be

Please sign in to comment.