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

FesTransaction.Commit - Update event handlers NullReferenceException [DNET476] #466

Closed
firebird-automations opened this issue Dec 19, 2012 · 9 comments

Comments

@firebird-automations
Copy link

Submitted by: devvvy (devvvy)

Relate to DNET689

Attachments:
firebird_commit_nullref.patch

Votes: 1

Stack:
> FirebirdSql.Data.FirebirdClient.dll!FirebirdSql.Data.Client.Native.FesTransaction.Commit() Line 249 C#⁠
FirebirdSql.Data.FirebirdClient.dll!FirebirdSql.Data.FirebirdClient.FbTransaction.Commit() Line 169 + 0xc bytes C#⁠
...

I ran into a (System.NullReferenceException: Object reference not set to an instance of an object) from FesTransaction.Commit, and I have no clue what's happenning... as my code from BeginTransaction to Commit is not-threaded...

public void Commit()
{
this.CheckTransactionState();

		lock \(this\.db\)
		\{
			// Clear the status vector
			this\.ClearStatusVector\(\);

			int trHandle = this\.handle;

			db\.FbClient\.isc\_commit\_transaction\(this\.statusVector, ref trHandle\);

			this\.handle = trHandle;

			this\.db\.ParseStatusVector\(this\.statusVector\);

			this\.db\.TransactionCount\-\-;

			if \(this\.Update \!= null\)
			\{
                this\.Update\(this, new EventArgs\(\)\); <\-\- Blows up here, this\.Update == null\!?\!? Suspect this is a threading issue? Any idea how this happenned? \(Nothing in my code references FesTransaction\.Update and whole BeginTransaction/Commit is not\-threaded\)
			\}

			this\.state = TransactionState\.NoTransaction;
		\}
	\}
@firebird-automations
Copy link
Author

Commented by: devvvy (devvvy)

I suspect I fixed the issue by putting a lock around all places where this.Transaction.Update is decremented and/or set to null:

lock (FirebirdSql.Data.Client.Native.FesTransaction.UpdateSyncRoot)
{
this.Transaction.Update -= this.TransactionUpdate;
this.TransactionUpdate = null;
}

And also in FesTransaction.Commit,

public void Commit()
{
...
lock (FirebirdSql.Data.Client.Native.FesTransaction.UpdateSyncRoot)
{
if (this.Update != null)
{
// CAUTION: I suspect there's some threading issue this.Update becomes null sometimes ...
this.Update(this, new EventArgs());
}
}
}
...
}

Can anyone confirm if this is a proper fix please? Thank you very much.

@firebird-automations
Copy link
Author

Commented by: @cincuranet

Can you confirm the issue is still happening with latest version (3.x)?

@firebird-automations
Copy link
Author

Commented by: devvvy (devvvy)

sorry i don't think i will have time to upgrade for coming few months.

@firebird-automations
Copy link
Author

Commented by: Jean-Pierre Schober (jpschober)

I run into the same problem and can confirm that it still exists in release 3.0.2.
It seems to be a threading problem regarding the Update event handler. I have attached a patch that should fix this.

@firebird-automations
Copy link
Author

Modified by: Jean-Pierre Schober (jpschober)

Attachment: firebird_commit_nullref.patch [ 12310 ]

@firebird-automations
Copy link
Author

Modified by: @cincuranet

Link: This issue relate to DNET689 [ DNET689 ]

@firebird-automations
Copy link
Author

Modified by: @cincuranet

status: Open [ 1 ] => In Progress [ 3 ]

@firebird-automations
Copy link
Author

Modified by: @cincuranet

status: In Progress [ 3 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

Fix Version: 5.0.5.0 [ 10760 ]

@firebird-automations
Copy link
Author

Modified by: @cincuranet

Fix Version: 5.0.0.0 [ 10744 ]

Fix Version: 5.0.5.0 [ 10760 ] =>

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

No branches or pull requests

2 participants