Description
Software versions
MySqlConnector version: 2.3.1
Server type (MySQL, MariaDB, Aurora, etc.) and version: AWS RDS MySQL
.NET version: 7.0
(Optional) ORM NuGet packages and versions:
Describe the bug
The cmd.ExecuteReaderAsync sometimes get NullException.
Source:
public async Task<GetNavigationBarBulletsContent> Get([FromServices] MySqlDataSource dbBroadcast )
{
await using var conn = await dbBroadcast.OpenConnectionAsync();
string qChannelsToScan = "SELECT channel_id FROM channels_members WHERE member_id = @my_id";
using var cmdChannelsToScan = new MySqlCommand(qChannelsToScan, conn);
cmdChannelsToScan.Parameters.AddWithValue("my_id", internal_id);
using var rdrChannelsToScan = await cmdChannelsToScan.ExecuteReaderAsync(); // Here is the NullException thrown
}
After this, it almost always throws a second error on the first opening of a connection:
MySqlConnector.MySqlProtocolException: Packet received out-of-order. Expected 1; got 2.
Exception
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HN09S7DON3PT", Request id "0HN09S7DON3PT:00000002": An unhandled exception was thrown by the application.
System.NullReferenceException: Object reference not set to an instance of an object.
at MySqlConnector.MySqlDataReader.ActivateResultSet(CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlDataReader.cs:line 133
at MySqlConnector.MySqlDataReader.InitAsync(CommandListPosition commandListPosition, ICommandPayloadCreator payloadCreator, IDictionary`2 cachedProcedures, IMySqlCommand command, CommandBehavior behavior, Activity activity, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlDataReader.cs:line 505
at MySqlConnector.Core.CommandExecutor.ExecuteReaderAsync(CommandListPosition commandListPosition, ICommandPayloadCreator payloadCreator, CommandBehavior behavior, Activity activity, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/CommandExecutor.cs:line 78
at MySqlConnector.MySqlCommand.ExecuteReaderAsync(CommandBehavior behavior, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlCommand.cs:line 358
at OUT_SL_PRO_API.Controllers.GetNavigationBarBullets.Get(MySqlDataSource dbBroadcast) in ...\Controllers\GetNavigationBarBullets.cs:line 45
at OUT_SL_PRO_API.Controllers.GetNavigationBarBullets.Get(MySqlDataSource dbBroadcast) in ...\Controllers\GetNavigationBarBullets.cs:line 136
at lambda_method112(Closure, Object)
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
This call is requested around 10 x per second continously. 99% goes well, 1% errors like above.
First, i used this in the function:
string conn_string = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build().GetSection("ConnectionStrings")["Broadcast"];
await using var conn = new MySqlConnection(conn_string);
I switch to the following, hoping it would help, but it did not:
Program:
builder.Services.AddMySqlDataSource(builder.Configuration.GetConnectionString("Broadcast"));
And in the Controller:
[FromServices] MySqlDataSource dbBroadcast