Bug #90845 | NullReferenceException on connection close | ||
---|---|---|---|
Submitted: | 12 May 2018 10:46 | Modified: | 20 Feb 2021 23:32 |
Reporter: | Francesco Cattoni | Email Updates: | |
Status: | No Feedback | Impact on me: | |
Category: | Connector / NET | Severity: | S3 (Non-critical) |
Version: | 8.0.11 | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | exception |
[12 May 2018 10:46]
Francesco Cattoni
[12 May 2018 11:11]
Francesco Cattoni
Sorry I forgot to write that the exception is thrown while Disposing of the MySqlCommand
[13 May 2018 17:13]
Bradley Grainger
This sounds similar to bug #89159. (But without a self-contained repro or full call stack, it's hard to say for sure.)
[13 May 2018 18:46]
Francesco Cattoni
Do you need a call stack?
[14 May 2018 11:59]
Chiranjeevi Battula
Hello Francesco, Thank you for the bug report. Could you please provide repeatable steps (exact steps/sample project, full stack trace etc. - please make it as private if you prefer) to confirm this issue at our end? Thanks, Chiranjeevi.
[15 May 2018 14:36]
Francesco Cattoni
Here it is. - MySql server version: 5.7.18-log Hosted on my local computer. - packages.config MySql.Data line: <package id="MySql.Data" version="8.0.11" targetFramework="net461" /> - Framework: .NET Framework v4.6.1 (tested as library in .NET 4.5.2 too) C# 7.0 - CPU architecture: My computer x64 Built as AnyCPU with "32 bit preferred" disabled - Code to reproduce [as NUnit test fixture]: using System; using System.Data; using MySql.Data.MySqlClient; using NUnit.Framework; namespace Tests { [TestFixture] public class MySqlBug { [Test] public void Diy() { MySqlConnectionStringBuilder connectionStringBuilder = new MySqlConnectionStringBuilder() { Server = "localhost", UserID = "root", Password = "foobar", Database = "tests", PersistSecurityInfo = true, Pooling = true, AllowUserVariables = true, ConvertZeroDateTime = true, SslMode = MySqlSslMode.None }; var conn = new MySqlConnection(connectionStringBuilder.GetConnectionString(true)); conn.Open(); Console.WriteLine(conn.ServerVersion); var command = new MySqlCommand("SELECT 1", conn); using (command) { var reader = command.ExecuteReader(CommandBehavior.CloseConnection); } } } } - Console output: Tests.MySqlBug.Diy System.NullReferenceException : Riferimento a un oggetto non impostato su un'istanza di oggetto. in MySql.Data.MySqlClient.MySqlConnection.set_Reader(MySqlDataReader value) in MySql.Data.MySqlClient.MySqlCommand.Dispose(Boolean disposing) in MySql.Data.MySqlClient.MySqlCommand.Dispose() in Tests.MySqlBug.Diy() in C:\_INGAGE\_Plugins\DataManager\Tests\MySqlBug.cs:riga 30 5.7.18-log Just ask if you need anything else.
[30 May 2018 6:26]
Chiranjeevi Battula
Hello Francesco Cattoni, Thank you for the bug report. Verified this behavior on Visual Studio 2017 and Connector/NET 8.0.11 version.. Thanks, Chiranjeevi.
[30 May 2018 6:26]
Chiranjeevi Battula
Screenshot
Attachment: Bug_90845.PNG (image/png, text), 109.35 KiB.
[4 Jun 2018 7:40]
Chiranjeevi Battula
http://bugs.mysql.com/bug.php?id=91106 marked as duplicate of this one.
[4 Jan 2019 8:59]
Oscar de Groot
This NullReferenceException can alo get thrown on Finalize(), i.e. when the MySqlDataReader is garbage collected. See https://bugs.mysql.com/bug.php?id=91106 (marked as duplicate of this bug) for an example. In this case, the entire client application is forced to terminate; there is no possibility whatsoever for the client to handle it gracefully. For that reason, could the Severity of this bug please be raised? For reference, the duplicate bug had S1 (Critical).
[20 Apr 2020 7:00]
IJsbrand Oudshoorn
I encounter the exact same bug. Same stack trace. Environment: Database server MySQL 8.0.19 running on Ubuntu Windows client target on Microsoft .Net 4.8 with latest Connector/NET 8.0.19. I have the same problem with Connector/NET 6.10.9 My current work around is to stay on Connector/NET 6.9.9
[7 Sep 2020 16:34]
chris pace
I am encountering the same issue. Will this be fixed? Should I fall back to a different version?
[20 Jan 2021 23:32]
Daniel Valdez
Hi, Can you please verify using the latest C/NET release, v8.0.23? Should be fixed. Daniel
[22 Jan 2021 10:37]
IJsbrand Oudshoorn
I can confirm for my scenario that this bug #90845 has been fixed in version 8.0.23 of NuGet package MySql.Data. Unfortunaly now having another issue. DataReader.Read throwing System.ArgumentOutOfRangeException "Non-negative number required." So I can't still update to latest package. I will research this new issue a bit further and comment or create new ticket for this if needed.
[22 Jan 2021 15:27]
Daniel Valdez
Given that this issue is no longer happening, I will proceed to close it and if there's another bug, please create a new report.
[16 Feb 2021 12:19]
Slava Tretyak
// There is actually one more issue. Probably related. // The null reference happens in reader.Dispoase after the EndOfStreamException is reader.Read() // here below is the test code with details static void test1() { // create a table and add 15-20 records with some big data // and then try to read it with the a reader and sleep (to simulate long processing) using (MySqlConnection c = new MySqlConnection(conn)) { c.Open(); using (MySqlCommand cmd = new MySqlCommand("some stored procedure or a simple sql", c)) { using (MySqlDataReader r = cmd.ExecuteReader()) { bool read = r.Read(); while (read) { var bigdata = (String)r["some big data"]; if (sleep > 0) { // let's imaging that it takes time to handle the received data. // so simulate it with a sleep. // better to use sleep more than 60 seconds. // 60 seconds is default parameter in mysql config for net_write_timeout Console.WriteLine($"sleeping {sleep} seconds..."); System.Threading.Thread.Sleep(sleep * 1000); } try { read = r.Read(); } catch (Exception ex) { // here we got the exception when the net_write_timeout exceeded // the exception can happen not at the first read but at some later - looks like depends on the amount of data // MySql.Data.MySqlClient.MySqlException (0x80004005): Fatal error encountered during data read. // --->MySql.Data.MySqlClient.MySqlException(0x80004005): Reading from the stream has failed. // --->System.IO.EndOfStreamException: Attempted to read past the end of the stream. // the exception happens because of the timeout configured on mysql side in parameter net_write_timeout // and it is OK that we got that exception - no issue here. // The issue is the next NullRefernceException which happens in reader.Dispose after that(see below) Console.WriteLine($"Failed to read from the reader: {ex.ToString()}"); read = false; } } } // HERE r.Dispose is called and it throws null reference exception. The dispose should not throw it. // the exception is the below. Happens on version 8.0.19 and 8.0.23 as well. // --->System.NullReferenceException: Object reference not set to an instance of an object. // at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32 & affectedRow, Int64 & insertedId) in MySQL.Data\src\NativeDriver.cs:line 487 // at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32 & affectedRows, Int64 & insertedId) in MySQL.Data\src\Driver.cs:line 400 // at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force) in MySQL.Data\src\Driver.cs:line 389 // at MySql.Data.MySqlClient.MySqlDataReader.NextResult() in MySQL.Data\src\datareader.cs:line 849 // at MySql.Data.MySqlClient.MySqlDataReader.Close() in MySQL.Data\src\datareader.cs:line 163 // at MySql.Data.MySqlClient.MySqlDataReader.Dispose(Boolean disposing) in MySQL.Data\src\datareader.cs:line 1075 // at MySql.Data.MySqlClient.MySqlDataReader.Dispose() in MySQL.Data\src\datareader.cs:line 1067 } } }
[21 Feb 2021 1:00]
Bugs System
No feedback was provided for this bug for over a month, so it is being suspended automatically. If you are able to provide the information that was originally requested, please do so and change the status of the bug back to "Open".
[6 May 2021 16:11]
Michael Janulaitis
This bug is occurring again in the latest build 8.0.24. Stack trace: at MySql.Data.MySqlClient.MySqlConnection.set_Reader(MySqlDataReader value) at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) at XPlatformWindowsShared.Data.MySqlBase.ExecuteQuery(String sqlcmd) in ...
[25 Apr 2023 18:06]
Gregory Fishbein
This bug is still occuring. Looking at the code, it is still possible for Dispose to throw a null reference exception because the driver is null in the DataReader or this line that sets the Reader to null could fail because the driver in the Connection is null. // always ensure internal reader is null (Bug #55558) _connection.Reader = null;