Skip to content

NullReferenceException in SNITCPHandle.Send #49

Closed

Description

@domisterwoozy

While attempting to write to a table using a table valued parameters with MARS on I am getting a NullReferenceException and the following stack trace.

System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Data.SqlClient.SNI.SNITCPHandle.Send(SNIPacket packet)
   at System.Data.SqlClient.SNI.SNIMarsConnection.Send(SNIPacket packet)
   at System.Data.SqlClient.SNI.SNIMarsHandle.SendControlPacket(SNISMUXFlags flags)
   at System.Data.SqlClient.SNI.SNIMarsHandle.Dispose()
   at System.Data.SqlClient.SNI.TdsParserStateObjectManaged.Dispose()
   at System.Data.SqlClient.TdsParserSessionPool.PutSession(TdsParserStateObject session)
   at System.Data.SqlClient.SqlCommand.EndExecuteNonQuery(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, 

I am on running dotnet-runtime-2.0.5-linux-x64.

Activity

  1. saurabh500 commented on Feb 20, 2018

    @saurabh500
    Collaborator

    @domisterwoozy What is the version of SqlClient that you are using?
    Can you post a repro application?

  2. AfsanehR-zz commented on Feb 22, 2018

    @AfsanehR-zz

    Hello @domisterwoozy. I wasn't able to repro the issue. Please see the attached file for a sample application that I ran with tvp and MARS enabled.
    https://gist.github.com/AfsanehR/a841749664520918035f6f42c5869351

    If you can post a repro, it would be useful to better investigate the issue you are facing.

  3. saurabh500 commented on Feb 26, 2018

    @saurabh500
    Collaborator

    Moving to Future as there is not enough actionable information available. @domisterwoozy a repro would really help us tackle the issue.

  4. danielearwicker commented on Jun 29, 2018

    @danielearwicker

    Since upgrading to 2.1 I've started getting this, also using TVPs, via ExecuteSqlCommand to do inserts and updates. I've noticed it when our system is under fairly large load e.g. when making 20 of these calls at the same time, and a successful call takes 20 secs (updates a lot of records in one hit), and often the other calls are either also throwing this NullReferenceException or else they're throwing timeout.

    So I guess this happens when you're recovering from another exception by unwinding the stack, and disposing something that isn't in an expected state?

    Stack trace comes at the problem from a slightly different route:

    System.NullReferenceException: Object reference not set to an instance of an object.
       at System.Data.SqlClient.SNI.SNITCPHandle.Send(SNIPacket packet)
       at System.Data.SqlClient.SNI.SNIMarsConnection.Send(SNIPacket packet)
       at System.Data.SqlClient.SNI.SNIMarsHandle.SendControlPacket(SNISMUXFlags flags)
       at System.Data.SqlClient.SNI.SNIMarsHandle.Dispose()
       at System.Data.SqlClient.SNI.TdsParserStateObjectManaged.Dispose()
       at System.Data.SqlClient.TdsParserSessionPool.PutSession(TdsParserStateObject session)
       at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
       at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite, String methodName)
       at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
       at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)
       at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
       at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.ExecuteSqlCommand(DatabaseFacade databaseFacade, RawSqlString sql, IEnumerable`1 parameters)
    
  5. AfsanehR-zz commented on Jun 29, 2018

    @AfsanehR-zz

    Do you also have the MARS ON in your setting? Would you be able to give us a repro, that would help us track down issue easier.

  6. zentron commented on Feb 5, 2019

    @zentron

    I have hit the same issue with 2.2.101 running on ubuntu (WSL). I will try and put together a simple repro and report back.

    Error Message:
     System.NullReferenceException : Object reference not set to an instance of an object.
    Stack Trace:
       at System.Data.SqlClient.SNI.SNITCPHandle.Send(SNIPacket packet)
       at System.Data.SqlClient.SNI.SNIMarsConnection.Send(SNIPacket packet)
       at System.Data.SqlClient.SNI.SNIMarsHandle.SendControlPacket(SNISMUXFlags flags)
       at System.Data.SqlClient.SNI.SNIMarsHandle.Dispose()
       at System.Data.SqlClient.SNI.TdsParserStateObjectManaged.Dispose()
       at System.Data.SqlClient.TdsParserSessionPool.PutSession(TdsParserStateObject session)
       at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
       at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite, String methodName)
       at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
    
  7. Spaceman1861 commented on Feb 8, 2019

    @Spaceman1861

    I have also hit the same issue.
    Don't have much to add tho.

    I'm running dotnetcore 2.1.5

    System.NullReferenceException: Object reference not set to an instance of an object. at System.Data.SqlClient.SNI.SNITCPHandle.Send(SNIPacket packet) at System.Data.SqlClient.SNI.SNIMarsConnection.Send(SNIPacket packet) at System.Data.SqlClient.SNI.SNIMarsHandle.SendControlPacket(SNISMUXFlags flags) at System.Data.SqlClient.SNI.SNIMarsHandle.Dispose() at System.Data.SqlClient.SNI.TdsParserStateObjectManaged.Dispose() at System.Data.SqlClient.TdsParserSessionPool.PutSession(TdsParserStateObject session) at System.Data.SqlClient.SqlCommand.EndExecuteNonQuery(IAsyncResult asyncResult) at System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task1 promise, Boolean requiresSynchronization)

  8. sdiakovskyi-gd commented on Apr 12, 2019

    @sdiakovskyi-gd

    It frequently reporducalbe with MARS enabled and high rate of concurrent queris.

    We are using latest images from
    microsoft/dotnet:2.2-runtime-deps-alpine
    and
    microsoft/dotnet:2.1-runtime-deps-alpine

    We are runing them on CentOS, and trying to conntect to AWS RDS instance, if it somehow helpful.

    Object reference not set to an instance of an object.

    at System.Data.SqlClient.SNI.SNITCPHandle.Send(SNIPacket packet) at System.Data.SqlClient.SNI.SNIMarsConnection.Send(SNIPacket packet) at System.Data.SqlClient.SNI.SNIMarsHandle.SendControlPacket(SNISMUXFlags flags) at System.Data.SqlClient.SNI.SNIMarsHandle.Dispose() at System.Data.SqlClient.SNI.TdsParserStateObjectManaged.Dispose() at System.Data.SqlClient.TdsParserSessionPool.PutSession(TdsParserStateObject session) at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite, String methodName) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()

  9. AfsanehR-zz commented on Apr 12, 2019

    @AfsanehR-zz

    @iwanttodie @Spaceman1861 @zentron if the issue is occurring often, do you think you can manage to provide a repro? This would help us with investigating the issue :) Thanks!

  10. transferred this issue fromdotnet/corefxon May 16, 2019
  11. divega commented on May 16, 2019

    @divega

    As recently announced in the .NET Blog, focus on new SqlClient features an improvements is moving to the new Microsoft.Data.SqlClient package. For this reason, we are moving this issue to the new repo at https://github.com/dotnet/SqlClient. We will still use https://github.com/dotnet/corefx to track issues on other providers like System.Data.Odbc and System.Data.OleDB, and general ADO.NET and .NET data access issues.

  12. added this to the 1.0.0 milestone on May 20, 2019
  13. Wraith2 commented on May 22, 2019

    @Wraith2
    Contributor

    If you can provide a reproduction i can investigate and probably fix this issue. Without a reproduction all i have to rely on is guesswork and that isn't an effective or efficient use of time so we may as well close the issue.

  14. modified the milestones: 1.0.0, on Jul 25, 2019
  15. cheenamalhotra commented on Oct 8, 2019

    @cheenamalhotra
    Member

    @domisterwoozy

    Please let us know if you're still facing this issue and provide more info on the use case, so we can reproduce at our end.

  16. johnsimons commented on Nov 7, 2019

    @johnsimons

    I am getting a very similar issue in netcoreapp 2.2 running on docker based on http://mcr.microsoft.com/dotnet/core/sdk:2.2 image
    With https://www.nuget.org/packages/System.Data.SqlClient/4.7.0

    System.NullReferenceException: Object reference not set to an instance of an object.
       at System.Data.SqlClient.SNI.SNIPacket.ReadFromStreamAsync(Stream stream, SNIAsyncCallback callback)
       at System.Data.SqlClient.SNI.SNITCPHandle.ReceiveAsync(SNIPacket& packet)
       at System.Data.SqlClient.SNI.SNIMarsConnection.ReceiveAsync(SNIPacket& packet)
       at System.Data.SqlClient.SNI.SNIMarsConnection.HandleReceiveComplete(SNIPacket packet, UInt32 sniErrorCode)
       at System.Data.SqlClient.SNI.SNIPacket.<ReadFromStreamAsync>g__ReadFromStreamAsync|27_0(SNIPacket packet, SNIAsyncCallback cb, ValueTask`1 valueTask)
    

    I seem to be able to repro it quite easily, but that is running our application, it will be quite difficult to repro it in isolation.

  17. yukiwongky commented on Nov 7, 2019

    @yukiwongky
    Contributor

    @johnsimons would be great if you can provide us with a repro script. Do you also encounter this error when trying to use TVP?

  18. johnsimons commented on Nov 8, 2019

    @johnsimons

    @yukiwongky, as I said, trying to create a small repro, is quite difficult for us. We have tried before but weren't able.
    However, we can offer you a pod in our Kubernetes Cluster that we can repro this issue in?

  19. cheenamalhotra commented on Nov 3, 2020

    @cheenamalhotra
    Member

    Closing this issue as no repro code is available and no new additional customers have reported this issue.
    Would recommend testing with Microsoft.Data.SqlClient latest versions (as significant changes are made to this driver in recent times) and open a new issue with repro application if reproduced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions