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 sqlstatistics and clientconnectionid #582

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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 @@ -360,7 +360,9 @@ public Guid ClientConnectionId
else
{
Task reconnectTask = _currentReconnectionTask;
if (reconnectTask != null && !reconnectTask.IsCompleted)
// Connection closed but previously open should return the correct ClientConnectionId
DbConnectionClosedPreviouslyOpened innerConnectionClosed = (InnerConnection as DbConnectionClosedPreviouslyOpened);
if ((reconnectTask != null && !reconnectTask.IsCompleted) || null != innerConnectionClosed)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this be better as

if ((reconnectTask != null && !reconnectTask.IsCompleted) || InnerConnection is DbConnectionClosedPreviouslyOpened)
{
   ...
}

? That way we're not doing the cast unless we have to, we're not adding an unnecessary local, etc.

{
return _originalConnectionId;
}
Expand Down Expand Up @@ -633,6 +635,7 @@ private void CloseInnerConnection()
// The SqlInternalConnectionTds is set to OpenBusy during close, once this happens the cast below will fail and
// the command will no longer be cancelable. It might be desirable to be able to cancel the close operation, but this is
// outside of the scope of Whidbey RTM. See (SqlCommand::Cancel) for other lock.
_originalConnectionId = ClientConnectionId;
InnerConnection.CloseConnection(this, ConnectionFactory);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ internal long SafeIncrement(ref long value)
internal void UpdateStatistics()
{
// update connection time
if (_closeTimestamp >= _openTimestamp)
if (_closeTimestamp >= _openTimestamp && long.MaxValue > _closeTimestamp - _openTimestamp)
{
SafeAdd(ref _connectionTime, _closeTimestamp - _openTimestamp);
_connectionTime = _closeTimestamp - _openTimestamp;
}
else
{
Expand Down