Skip to content

Commit

Permalink
FIX | Throwing exception from Dispose should not happen (#920)
Browse files Browse the repository at this point in the history
* Adding catch block to prevent dispose to throw

* Moving try/catch block inside Dispose

* Adding Parity to netfx and add error message and stack trace to the log

Co-authored-by: jJRahnama <[email protected]>
  • Loading branch information
Javad and jJRahnama authored Feb 23, 2021
1 parent 4fae95f commit cdf423f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -834,11 +834,18 @@ private void CleanPartialReadReliable()
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/Dispose/*' />
protected override void Dispose(bool disposing)
{
if (disposing)
try
{
Close();
if (disposing)
{
Close();
}
base.Dispose(disposing);
}
catch(SqlException ex)
{
SqlClientEventSource.Log.TryTraceEvent("SqlDataReader.Dispose | ERR | Error Message: {0}, Stack Trace: {1}", ex.Message, ex.StackTrace);
}
base.Dispose(disposing);
}

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/Close/*' />
Expand Down Expand Up @@ -2966,7 +2973,7 @@ override public int GetValues(object[] values)
if ((sequentialAccess) && (i < maximumColumn))
{
_data[fieldIndex].Clear();
if (fieldIndex > i && fieldIndex>0)
if (fieldIndex > i && fieldIndex > 0)
{
// if we jumped an index forward because of a hidden column see if the buffer before the
// current one was populated by the seek forward and clear it if it was
Expand Down Expand Up @@ -4515,7 +4522,7 @@ out bytesRead
if (!isContinuation)
{
// This is the first async operation which is happening - setup the _currentTask and timeout
Debug.Assert(context._source==null, "context._source should not be non-null when trying to change to async");
Debug.Assert(context._source == null, "context._source should not be non-null when trying to change to async");
source = new TaskCompletionSource<int>();
Task original = Interlocked.CompareExchange(ref _currentTask, source.Task, null);
if (original != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,23 @@ private void CleanPartialReadReliable()
}
}

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/Dispose/*' />
protected override void Dispose(bool disposing)
{
try
{
if (disposing)
{
Close();
}
base.Dispose(disposing);
}
catch (SqlException ex)
{
SqlClientEventSource.Log.TryTraceEvent("SqlDataReader.Dispose | ERR | Error Message: {0}, Stack Trace: {1}", ex.Message, ex.StackTrace);
}
}

/// <include file='..\..\..\..\..\..\..\doc\snippets\Microsoft.Data.SqlClient\SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/Close/*' />
override public void Close()
{
Expand Down

0 comments on commit cdf423f

Please sign in to comment.