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 (#1882)
  • Loading branch information
DavoudEshtehari committed Jan 11, 2023
1 parent f046489 commit c585669
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 @@ -115,7 +116,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 c585669

Please sign in to comment.