Skip to content

Commit

Permalink
Fix Async thread blocking on SqlConnection open for AAD modes
Browse files Browse the repository at this point in the history
Backporting dotnet#1182 for 3.0.1-servicing
  • Loading branch information
Kaur-Parminder committed Aug 21, 2021
1 parent 8908b92 commit d104762
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ protected override void Dispose(bool disposing)
}
base.Dispose(disposing);
}
catch(SqlException ex)
catch (SqlException ex)
{
SqlClientEventSource.Log.TryTraceEvent("SqlDataReader.Dispose | ERR | Error Message: {0}, Stack Trace: {1}", ex.Message, ex.StackTrace);
}
Expand Down Expand Up @@ -3767,26 +3767,18 @@ private bool TryReadColumnInternal(int i, bool readHeaderOnly = false)
_sharedState._nextColumnDataToRead = _sharedState._nextColumnHeaderToRead;
_sharedState._nextColumnHeaderToRead++; // We read this one

if (isNull)
// Trigger new behavior for RowVersion to send DBNull.Value by allowing entry for Timestamp or discard entry for Timestamp for legacy support.
// if LegacyRowVersionNullBehavior is enabled, Timestamp type must enter "else" block.
if (isNull && (!LocalAppContextSwitches.LegacyRowVersionNullBehavior || columnMetaData.type != SqlDbType.Timestamp))
{
if (columnMetaData.type == SqlDbType.Timestamp)
{
if (!LocalAppContextSwitches.LegacyRowVersionNullBehavior)
{
_data[i].SetToNullOfType(SqlBuffer.StorageType.SqlBinary);
}
}
else
{
TdsParser.GetNullSqlValue(_data[_sharedState._nextColumnDataToRead],
columnMetaData,
TdsParser.GetNullSqlValue(_data[_sharedState._nextColumnDataToRead],
columnMetaData,
_command != null ? _command.ColumnEncryptionSetting : SqlCommandColumnEncryptionSetting.UseConnectionSetting,
_parser.Connection);

if (!readHeaderOnly)
{
_sharedState._nextColumnDataToRead++;
}
if (!readHeaderOnly)
{
_sharedState._nextColumnDataToRead++;
}
}
else
Expand Down Expand Up @@ -4098,8 +4090,8 @@ internal bool TrySetMetaData(_SqlMetaDataSet metaData, bool moreInfo)

if (_parser != null)
{ // There is a valid case where parser is null
// Peek, and if row token present, set _hasRows true since there is a
// row in the result
// Peek, and if row token present, set _hasRows true since there is a
// row in the result
byte b;
if (!_stateObj.TryPeekByte(out b))
{
Expand Down Expand Up @@ -5021,7 +5013,7 @@ override public Task<T> GetFieldValueAsync<T>(int i, CancellationToken cancellat
{
_stateObj._shouldHaveEnoughData = true;
#endif
return Task.FromResult(GetFieldValueInternal<T>(i));
return Task.FromResult(GetFieldValueInternal<T>(i));
#if DEBUG
}
finally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5429,6 +5429,10 @@ internal static object GetNullSqlValue(SqlBuffer nullVal, SqlMetaDataPriv md, Sq
break;

case SqlDbType.Timestamp:
if (!LocalAppContextSwitches.LegacyRowVersionNullBehavior)
{
nullVal.SetToNullOfType(SqlBuffer.StorageType.SqlBinary);
}
break;

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4279,26 +4279,18 @@ private bool TryReadColumnInternal(int i, bool readHeaderOnly = false)
_sharedState._nextColumnDataToRead = _sharedState._nextColumnHeaderToRead;
_sharedState._nextColumnHeaderToRead++; // We read this one

if (isNull)
// Trigger new behavior for RowVersion to send DBNull.Value by allowing entry for Timestamp or discard entry for Timestamp for legacy support.
// if LegacyRowVersionNullBehavior is enabled, Timestamp type must enter "else" block.
if (isNull && (!LocalAppContextSwitches.LegacyRowVersionNullBehavior || columnMetaData.type != SqlDbType.Timestamp))
{
if (columnMetaData.type == SqlDbType.Timestamp)
{
if (!LocalAppContextSwitches.LegacyRowVersionNullBehavior)
{
_data[i].SetToNullOfType(SqlBuffer.StorageType.SqlBinary);
}
}
else
{
TdsParser.GetNullSqlValue(_data[_sharedState._nextColumnDataToRead],
TdsParser.GetNullSqlValue(_data[_sharedState._nextColumnDataToRead],
columnMetaData,
_command != null ? _command.ColumnEncryptionSetting : SqlCommandColumnEncryptionSetting.UseConnectionSetting,
_parser.Connection);

if (!readHeaderOnly)
{
_sharedState._nextColumnDataToRead++;
}
if (!readHeaderOnly)
{
_sharedState._nextColumnDataToRead++;
}
}
else
Expand Down
Loading

0 comments on commit d104762

Please sign in to comment.