Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix | Add thread safety with transient error list on configurable retry logic #1882

Merged
merged 1 commit into from
Jan 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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