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 in GetServerTransactionLevel #1121

Closed
ShaneCourtrille opened this issue Jun 16, 2021 · 5 comments · Fixed by #1122
Closed

Null Reference in GetServerTransactionLevel #1121

ShaneCourtrille opened this issue Jun 16, 2021 · 5 comments · Fixed by #1122

Comments

@ShaneCourtrille
Copy link

I'm investigating an exception occurring when our system is under load and wanted to know if anyone has any idea what could cause the following? From reading the code it looks like the _innerConnection.Owner must be null but not sure what would cause that?

System.NullReferenceException:
   at Microsoft.Data.SqlClient.SqlInternalTransaction.GetServerTransactionLevel (Microsoft.Data.SqlClient, Version=2.0.20168.4, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5)
   at Microsoft.Data.SqlClient.SqlInternalTransaction.CheckTransactionLevelAndZombie (Microsoft.Data.SqlClient, Version=2.0.20168.4, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5)
   at Microsoft.Data.SqlClient.SqlInternalTransaction.Commit (Microsoft.Data.SqlClient, Version=2.0.20168.4, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5)
   at Microsoft.Data.SqlClient.SqlTransaction.Commit (Microsoft.Data.SqlClient, Version=2.0.20168.4, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5)
   at YesSql.Session.CommitTransaction (YesSql.Core, Version=0.0.0.0, Culture=neutral, PublicKeyToken=51cdb8c1938e4789)
   at YesSql.Session+<CommitAsync>d__39.MoveNext (YesSql.Core, Version=0.0.0.0, Culture=neutral, PublicKeyToken=51cdb8c1938e4789)
@sebastienros
Copy link
Member

sebastienros commented Jun 16, 2021

_innerConnection.Owner points to this code:
https://referencesource.microsoft.com/#System.Data/fx/src/data/System/Data/ProviderBase/DbConnectionInternal.cs,294

Which is a WeakReference so I believe the getter should create a local copy of Target and check for nullability.

https://referencesource.microsoft.com/#System.Data/fx/src/data/System/Data/ProviderBase/DbConnectionInternal.cs,39

@sebastienros
Copy link
Member

Could also show a race in the pooling logic since reports of this issue seem to relate to high load.

@Wraith2
Copy link
Contributor

Wraith2 commented Jun 16, 2021

use of WeakReference should be converted to WeakReference<T> if possible because the generic version has a usage pattern designed to avoid this sort of problem with time of check time of use dsparity.

@ShaneCourtrille
Copy link
Author

The current code also loses the original exception which from our point of view is the most important one.

@ShaneCourtrille
Copy link
Author

FYI the problem went away after we 1) increased the Min threads in ThreadPool 2) fixed Redis timeouts.. I'm not yet sure if 2) was causing the db transaction to timeout/fail which might be the cause.

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

Successfully merging a pull request may close this issue.

3 participants