8000 Sometimes: Object Null Exception when using var rdr = await cmd.ExecuteReaderAsync(); · Issue #1427 · mysql-net/MySqlConnector · GitHub
[go: up one dir, main page]

Skip to content

Sometimes: Object Null Exception when using var rdr = await cmd.ExecuteReaderAsync(); #1427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
stephanOUT opened this issue Dec 31, 2023 · 3 comments

Comments

@stephanOUT
Copy link

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

@bgrainger
Copy link
Member

The NullReferenceException is very likely an indication of library misuse, such as using the same object on multiple threads; this is not permitted: https://mysqlconnector.net/troubleshooting/connection-reuse/.

Is the code snippet you posted the actual code being run? It doesn't appear to line up with the exception message line numbers, which indicates that it might be a much longer function:

     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

@bgrainger bgrainger added the waiting for answer Needs more information from the bug reporter label Jan 14, 2024
@bgrainger bgrainger closed this as not planned Won't fix, can't repro, duplicate, stale Feb 4, 2024
@bgrainger bgrainger added duplicate and removed waiting for answer Needs more information from the bug reporter labels Apr 22, 2024
@bgrainger
Copy link
Member

Further discussion on #1459.

@bgrainger bgrainger reopened this Apr 22, 2024
@bgrainger
Copy link
Member

Duplicate of #1459

@bgrainger bgrainger marked this as a duplicate of #1459 Apr 22, 2024
@bgrainger bgrainger closed this as not planned Won't fix, can't repro, duplicate, stale Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants
0