Skip to content

ServerSession.FinishQuerying throws InvalidOperationException due to possible race #1341

Closed
@bgrainger

Description

@bgrainger

Software versions
MySqlConnector version: 2.2.2
Server type (MySQL, MariaDB, Aurora, etc.) and version: AzureDatabase for MySQL 5.7
.NET version: .NET Framework 4.7.2
(Optional) ORM NuGet packages and versions: Dapper 1.60.6

Describe the bug

ServerSession.FinishQuerying throws an InvalidOperationException.

Exception

System.InvalidOperationException: Expected state to be Failed but was CancelingQuery.
   at void MySqlConnector.Core.ServerSession.VerifyState(State state) in /_/src/MySqlConnector/Core/ServerSession.cs:line 1797
   at void MySqlConnector.Core.ServerSession.FinishQuerying() in /_/src/MySqlConnector/Core/ServerSession.cs:line 328
   at void MySqlConnector.MySqlConnection.FinishQuerying(bool hasWarnings) in /_/src/MySqlConnector/MySqlConnection.cs:line 885
   at async Task MySqlConnector.MySqlDataReader.DisposeAsync(IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlDataReader.cs:line 631
   at void MySqlConnector.MySqlDataReader.Dispose(bool disposing) in /_/src/MySqlConnector/MySqlDataReader.cs:line 439
   at async Task<int> MySqlConnector.MySqlCommand.ExecuteNonQueryAsync(IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlCommand.cs:line 303
   at async Task<int> Dapper.SqlMapper.ExecuteImplAsync(IDbConnection cnn, CommandDefinition command, object param) in C:/projects/dapper/Dapper/SqlMapper.Async.cs:line 678

Expected behavior

No exception. Query should be cancelled successfully (if cancellation happens).

Additional context

There may be a race condition between here and here.

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