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

perf: Lazy init reconnect lock when needed #379

Merged
merged 1 commit into from
Feb 5, 2020
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 @@ -45,7 +45,7 @@ public sealed partial class SqlConnection : DbConnection, ICloneable
private string _accessToken; // Access Token to be used for token based authententication

// connection resiliency
private object _reconnectLock = new object();
private object _reconnectLock;
internal Task _currentReconnectionTask;
private Task _asyncWaitingForReconnection; // current async task waiting for reconnection in non-MARS connections
private Guid _originalConnectionId = Guid.Empty;
Expand Down Expand Up @@ -1116,6 +1116,12 @@ internal Task ValidateAndReconnect(Action beforeDisconnect, int timeout)
if (cData._unrecoverableStatesCount == 0)
{
bool callDisconnect = false;

if (_reconnectLock is null)
{
Interlocked.CompareExchange(ref _reconnectLock, new object(), null);
}

lock (_reconnectLock)
{
tdsConn.CheckEnlistedTransactionBinding();
Expand Down