Skip to content

Fix NullReferenceException when disposing transactions (race conditon (?)) - #573

Merged
roji merged 1 commit into
npgsql:2.2from
havard:2.2
Apr 6, 2015
Merged

roji merged 1 commit into
npgsql:2.2from
havard:2.2

Conversation

@havard

@havard havard commented Apr 6, 2015

Copy link
Copy Markdown

When running in a relatively heavy load scenario, Npgsql will occasionally (very rarely) fail when disposing transactions that aborted prematurely. I am unable to reproduce the issue consistently, but have a patch which (I think) fixes the problem.

When this exception occurs the logged stack trace I am seeing is this:

An exception of type System.NullReferenceException was thrown: Object reference not set to an instance of an object. 
Stack trace: 
  at Npgsql.NpgsqlTransaction.Dispose(Boolean disposing) 
  at System.Data.Common.DbTransaction.Dispose()
  at System.Data.Entity.Infrastructure.Interception.DbTransactionDispatcher.b__12(DbTransaction t, DbTransactionInterceptionContext c) 
  at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
  at System.Data.Entity.Infrastructure.Interception.DbTransactionDispatcher.Dispose(DbTransaction transaction, DbInterceptionContext interceptionContext) 
  at System.Data.Entity.Core.EntityClient.EntityTransaction.Dispose(Boolean disposing) at System.Data.Common.DbTransaction.Dispose() 
  at System.Data.Entity.Core.Objects.ObjectContext.d__3d`1.MoveNext()

This pull request guards against NpgsqlConnector references being null. I cannot be certain that the connector reference is the culprit, but since running with the patch in place I have not observed any more NullReferenceExceptions.

roji added a commit that referenced this pull request Apr 6, 2015
Fix NullReferenceException when disposing transactions (race conditon (?))
@roji
roji merged commit 9bbb1f2 into npgsql:2.2 Apr 6, 2015
@roji roji added this to the 2.2.6 milestone Apr 6, 2015
@roji roji added the bug label Apr 6, 2015
@roji

roji commented Apr 6, 2015

Copy link
Copy Markdown
Member

Thanks for submitting this. Like many others this area of the code has undergone a lot of change in our master branch for the upcoming v3 release. I worked hard to clean up several state issues in master but I can't be sure some aren't left.

If you have any spare time, it would be great if you could give our master branch a spin and report on the results...

@havard

havard commented Apr 6, 2015

Copy link
Copy Markdown
Author

Thanks for pulling. I will try to find time to give master a spin.

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 this pull request may close these issues.

2 participants