Skip to content

Commit 88551da

Browse files
committed
By defensive with command and reader access due to issues with MySQL 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
1 parent 98f4a94 commit 88551da

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/EFCore.Relational/Storage/RelationalDataReader.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,22 @@ public virtual void Dispose()
111111
{
112112
if (!_disposed)
113113
{
114+
// Defensively read RecordsAffected since MySQL provider can throw ObjectDisposedException
115+
var recordsAffected = -1;
116+
try
117+
{
118+
recordsAffected = _reader.RecordsAffected;
119+
}
120+
catch
121+
{
122+
}
123+
114124
_logger.DataReaderDisposing(
115125
_connection,
116126
_command,
117127
_reader,
118128
_commandId,
119-
_reader.RecordsAffected,
129+
recordsAffected,
120130
_readCount,
121131
_startTime,
122132
_stopwatch.Elapsed);
@@ -125,7 +135,7 @@ public virtual void Dispose()
125135
if (!AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue9277", out var isEnabled)
126136
|| !isEnabled)
127137
{
128-
_command.Parameters.Clear();
138+
_command.Parameters?.Clear();
129139
}
130140
_command.Dispose();
131141
_connection?.Close();

0 commit comments

Comments
 (0)