Skip to content

Commit

Permalink
By defensive with command and reader access due to issues with MySQL …
Browse files Browse the repository at this point in the history
…provider

Issue #10147

* MySQL provider sometimes has null Parameters collection
* MySQL provider sometimes throws when asking for records affected

Fix is to be defensive in our code and we will file issues on MySQL provider
  • Loading branch information
ajcvickers committed Oct 24, 2017
1 parent 98f4a94 commit 88551da
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/EFCore.Relational/Storage/RelationalDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,22 @@ public virtual void Dispose()
{
if (!_disposed)
{
// Defensively read RecordsAffected since MySQL provider can throw ObjectDisposedException
var recordsAffected = -1;
try
{
recordsAffected = _reader.RecordsAffected;
}
catch
{
}

_logger.DataReaderDisposing(
_connection,
_command,
_reader,
_commandId,
_reader.RecordsAffected,
recordsAffected,
_readCount,
_startTime,
_stopwatch.Elapsed);
Expand All @@ -125,7 +135,7 @@ public virtual void Dispose()
if (!AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue9277", out var isEnabled)
|| !isEnabled)
{
_command.Parameters.Clear();
_command.Parameters?.Clear();
}
_command.Dispose();
_connection?.Close();
Expand Down

0 comments on commit 88551da

Please sign in to comment.