Bug #107110 System.NullReferenceException
Submitted: 24 Apr 2022 9:18 Modified: 29 Aug 2022 15:34
Reporter: vic lee Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:8.0.28 OS:Any
Assigned to: CPU Architecture:Any
Tags: Null Reference Exception

[24 Apr 2022 9:18] vic lee
Description:
When an exception occurs during the execution of the SQL statement, the transaction rollback occurs with a null reference exception, which causes the Web server(IIS) process to crash.mysql server version is 5.7.33

How to repeat:
class Program
    {
        static void Main(string[] args)
        {
            string connStr = "server=192.168.0.245;User Id=root;password=***;Persist Security Info=True;database=appdb;Maximum Pool Size=150;Allow User Variables=True;Logging=True;";

            using (TransactionScope scope = new TransactionScope())
            {

                using (var connection = new MySqlConnection(connStr))
                {
                    connection.Open();
                    using (var cmd = connection.CreateCommand())
                    {

                        cmd.CommandText = "SELECT * from INFORMATION_SCHEMA.TABLES LIMIT 1; SELECT SLEEP(5);";
                        cmd.CommandTimeout = 1;
                        cmd.ExecuteNonQuery();
                    }

                }
            }

        }
    }
[24 Apr 2022 10:04] vic lee
<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>131077</EventID><Type>3</Type><SubType Name="Critical">0</SubType><Level>1</Level><TimeCreated SystemTime="2022-04-23T09:09:21.4886797Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" /><Execution ProcessName="w3wp" ProcessID="13872" ThreadID="812" /><Channel /><Computer>WEBSERVER</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord Severity="Critical" Channel="Operational" xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord"><TraceIdentifier>http://msdn.microsoft.com/zh-CN/library/System.ServiceModel.Diagnostics.UnhandledException...><Description>未经处理的异常。异常的详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
   在 MySql.Data.MySqlClient.NativeDriver.ExecutePacket(MySqlPacket packetToExecute)
   在 MySql.Data.MySqlClient.NativeDriver.SendQuery(MySqlPacket queryPacket, Int32 paramsPosition)
   在 MySql.Data.MySqlClient.Driver.SendQuery(MySqlPacket p, Int32 paramsPosition)
   在 MySql.Data.MySqlClient.Statement.ExecuteNext()
   在 MySql.Data.MySqlClient.PreparableStatement.Execute()
   在 MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   在 MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
   在 MySql.Data.MySqlClient.MySqlTransaction.Rollback()
   在 MySql.Data.MySqlClient.MySqlTransactionScope.Rollback(SinglePhaseEnlistment singlePhaseEnlistment)
   在 MySql.Data.MySqlClient.MySqlPromotableTransaction.System.Transactions.IPromotableSinglePhaseNotification.Rollback(SinglePhaseEnlistment singlePhaseEnlistment)
   在 System.Transactions.DurableEnlistmentAborting.EnterState(InternalEnlistment enlistment)
   在 System.Transactions.TransactionStateAborted.EnterState(InternalTransaction tx)
   在 System.Transactions.EnlistableStates.Timeout(InternalTransaction tx)
   在 System.Transactions.Bucket.TimeoutTransactions()
   在 System.Transactions.BucketSet.TimeoutTransactions()
   在 System.Transactions.TransactionTable.ThreadTimer(Object state)
   在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   在 System.Threading.TimerQueueTimer.CallCallback()
   在 System.Threading.TimerQueueTimer.Fire()
   在 System.Threading.TimerQueue.FireNextTimers()</Description><AppDomain>/LM/W3SVC/3/ROOT-2-132951059638637273</AppDomain><Exception><ExceptionType>System.NullReferenceException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>未将对象引用设置到对象的实例。</Message><StackTrace>   在 MySql.Data.MySqlClient.NativeDriver.ExecutePacket(MySqlPacket packetToExecute)
   在 MySql.Data.MySqlClient.NativeDriver.SendQuery(MySqlPacket queryPacket, Int32 paramsPosition)
   在 MySql.Data.MySqlClient.Driver.SendQuery(MySqlPacket p, Int32 paramsPosition)
   在 MySql.Data.MySqlClient.Statement.ExecuteNext()
   在 MySql.Data.MySqlClient.PreparableStatement.Execute()
   在 MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   在 MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
   在 MySql.Data.MySqlClient.MySqlTransaction.Rollback()
   在 MySql.Data.MySqlClient.MySqlTransactionScope.Rollback(SinglePhaseEnlistment singlePhaseEnlistment)
   在 MySql.Data.MySqlClient.MySqlPromotableTransaction.System.Transactions.IPromotableSinglePhaseNotification.Rollback(SinglePhaseEnlistment singlePhaseEnlistment)
   在 System.Transactions.DurableEnlistmentAborting.EnterState(InternalEnlistment enlistment)
   在 System.Transactions.TransactionStateAborted.EnterState(InternalTransaction tx)
   在 System.Transactions.EnlistableStates.Timeout(InternalTransaction tx)
   在 System.Transactions.Bucket.TimeoutTransactions()
   在 System.Transactions.BucketSet.TimeoutTransactions()
   在 System.Transactions.TransactionTable.ThreadTimer(Object state)
   在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   在 System.Threading.TimerQueueTimer.CallCallback()
   在 System.Threading.TimerQueueTimer.Fire()
   在 System.Threading.TimerQueue.FireNextTimers()</StackTrace><ExceptionString>System.NullReferenceException: 未将对象引用设置到对象的实例。
   在 MySql.Data.MySqlClient.NativeDriver.ExecutePacket(MySqlPacket packetToExecute)
   在 MySql.Data.MySqlClient.NativeDriver.SendQuery(MySqlPacket queryPacket, Int32 paramsPosition)
   在 MySql.Data.MySqlClient.Driver.SendQuery(MySqlPacket p, Int32 paramsPosition)
   在 MySql.Data.MySqlClient.Statement.ExecuteNext()
   在 MySql.Data.MySqlClient.PreparableStatement.Execute()
   在 MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   在 MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
   在 MySql.Data.MySqlClient.MySqlTransaction.Rollback()
   在 MySql.Data.MySqlClient.MySqlTransactionScope.Rollback(SinglePhaseEnlistment singlePhaseEnlistment)
   在 MySql.Data.MySqlClient.MySqlPromotableTransaction.System.Transactions.IPromotableSinglePhaseNotification.Rollback(SinglePhaseEnlistment singlePhaseEnlistment)
   在 System.Transactions.DurableEnlistmentAborting.EnterState(InternalEnlistment enlistment)
   在 System.Transactions.TransactionStateAborted.EnterState(InternalTransaction tx)
   在 System.Transactions.EnlistableStates.Timeout(InternalTransaction tx)
   在 System.Transactions.Bucket.TimeoutTransactions()
   在 System.Transactions.BucketSet.TimeoutTransactions()
   在 System.Transactions.TransactionTable.ThreadTimer(Object state)
   在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   在 System.Threading.TimerQueueTimer.CallCallback()
   在 System.Threading.TimerQueueTimer.Fire()
   在 System.Threading.TimerQueue.FireNextTimers()</ExceptionString></Exception></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent>
[24 Apr 2022 12:50] MySQL Verification Team
Hello vic lee,

Thank you for the report.

regards,
Umesh
[29 Aug 2022 15:34] Christine Cole
Posted by developer:
 
Fixed as of the upcoming MySQL Connector/NET 8.0.31 release, and here's the proposed changelog entry from the documentation team:

If an exception occurred during the execution of a SQL statement within a
transaction, the subsequent transaction rollback produced a null reference
exception, which could cause the Web server (IIS) process to halt
unexpectedly. This fix changes the way the connection object manages
rollback behavior.

Thank you for the bug report.