Skip to content

NullReferenceException in MySqlConnection.Cancel  #1506

@dmathijs

Description

@dmathijs

MySqlConnector version: 2.3.1
Server type (MySQL, MariaDB, Aurora, etc.) and version: MariaDb
.NET version: 8.0.302
(Optional) ORM NuGet packages and versions: Pomelo.EntityFrameworkCore.MySql

Today I got this stacktrace on my server:

Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at MySqlConnector.MySqlConnection.Cancel(ICancellableCommand command, Int32 commandId, Boolean isCancel) in /_/src/MySqlConnector/MySqlConnection.cs:line 762
   at MySqlConnector.MySqlCommand.CancelCommandForTimeout() in /_/src/MySqlConnector/MySqlCommand.cs:line 439
   at MySqlConnector.Utilities.TimerQueue.Callback(Object obj) in /_/src/MySqlConnector/Utilities/TimerQueue.cs:line 98
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.TimerQueueTimer.Fire(Boolean isThreadPool)
   at System.Threading.TimerQueue.FireNextTimers()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()

I noticed that back in 2022, there was a fix done for this exact issue:

However, this seems to be re-factored away and it seems like this bug was re-introduced at some point.
000f586
e82f091

The problem is that I don't know enough about the code-base to know whether adding null conditional operators is allowed, can someone give me some pointers?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions