Skip to content
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

Null Reference Exception #988

Closed
msallin opened this issue Mar 16, 2021 · 7 comments
Closed

Null Reference Exception #988

msallin opened this issue Mar 16, 2021 · 7 comments

Comments

@msallin
Copy link

msallin commented Mar 16, 2021

We discovered the following NullReferenceException.
The command which is executed is executed every hour and deletes some records.
The code runs already for about a year exactly like this and we only saw this exception once.

One interesting detail:
The incoming HTTP request is logged at 8:15:07.000 AM and the exception at 8:17:10.049 AM

Exception message: System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Data.SqlClient.SNI.TdsParserStateObjectManaged.ReleasePacket(PacketHandle syncReadPacket)
   at Microsoft.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync()
   at Microsoft.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket()
   at Microsoft.Data.SqlClient.TdsParserStateObject.TryPrepareBuffer()
   at Microsoft.Data.SqlClient.TdsParserStateObject.TryReadByte(Byte& value)
   at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at Microsoft.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at Microsoft.Data.SqlClient.TdsParser.ProcessAttention(TdsParserStateObject stateObj)
   at Microsoft.Data.SqlClient.TdsParserStateObject.ResetCancelAndProcessAttention()
   at Microsoft.Data.SqlClient.TdsParserStateObject.CloseSession()
   at Microsoft.Data.SqlClient.SqlCommand.EndExecuteNonQueryAsync(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location ---
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteNonQueryAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteNonQueryAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteNonQueryAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.ExecuteSqlRawAsync(DatabaseFacade databaseFacade, String sql, IEnumerable`1 parameters, CancellationToken cancellationToken)
   at OurAppCore.Persistence.AppDbContext.<>c__DisplayClass30_0.<<DeleteOldRecordsInBatches>b__0>d.MoveNext() in -:line 53
--- End of stack trace from previous location ---
   at OurAppCore.Persistence.BatchOperationStrategy.ExecuteBatchOperation(Func`1 command, Int32 batchSize, CancellationToken cancellationToken) in -:line 16
   at OurAppFeatures.VolleAdresseRecordsCollection.Housekeeping.VolleAdresseRecordsHousekeeping.CleanupAsync(CancellationToken cancellationToken) in -:line 56
   at OurAppFeatures.VolleAdresseRecordsCollection.Housekeeping.HousekeepingController.Cleanup(RunJobCommand runJobCommand) in -:line 24
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(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.<InvokeFilterPipelineAsync>g__Awaited|19_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.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)"

To reproduce

We are not able to reproduce it.

Expected behavior

No null reference exception is thrown.

Further technical details

Microsoft.Data.SqlClient version: Microsoft.Data.SqlClient, Version=2.0.20168.4, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5
.NET target: .NET 5
SQL Server version: SQL Server 2019
Operating system: Docker Container (Alpine Linux)

@Wraith2
Copy link
Contributor

Wraith2 commented Mar 16, 2021

Can you tell us which version of the library, and which library you're using? I remember that there were some changes recently to make releasepacket safer in edge cases which might fix this issue.

@msallin
Copy link
Author

msallin commented Mar 16, 2021

I posted the version of the Microsoft.Data.SqlClient already in the issue.
Which additional information do you need?

@ErikEJ
Copy link
Contributor

ErikEJ commented Mar 16, 2021

Your csproj would be nice.

@msallin
Copy link
Author

msallin commented Mar 16, 2021

Unfortunately, this will not be helpful. But I guess this is what you are looking for?

image

@ErikEJ
Copy link
Contributor

ErikEJ commented Mar 16, 2021

Very helpful!

Add an explicit reference to MDS 2.1.2

@Wraith2
Copy link
Contributor

Wraith2 commented Mar 16, 2021

I'm not sure how I missed the version number. @ErikEJ has the correct solution I think, force the use of the latest package and that should resolve it if it's the recently fixed issue.

@msallin
Copy link
Author

msallin commented Mar 16, 2021

Thanks for your help. I assume that EF.Core is going to update the dependency to MSD 2.1.2 and as we saw this exception only one time, I will not explicitly set the reference but wait.
However, if we see this exception more often, I will update to MSD 2.1.2 and let you know if the exception occurs again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants