SCM

[#1011305] Scope without prepared transactions

View Trackers | Patches | Download .csv | Monitor

Date:
2013-02-14 11:34
Priority:
3
State:
Open
Submitted by:
Francisco Figueiredo jr. (fxjr)
Assigned to:
Nobody (None)
Category:
None
Group:
None
Resolution:
None
 
Summary:
Scope without prepared transactions

Detailed description

Transcript of bug report and patch on github: https://github.com/franciscojunior/Npgsql2/pull/8

Hey Francisco and Josh, sorry for disappearing, had some busy times at work.

Here's an attempt at a patch which would remove the dependency on prepared transactions when a connection is closed within a TransactionScope. I added a unit test which reproduced the problem on stock Postgres installations: SystemTransactionTests.SimpleTransactionScopeWithImplicitEnlist.

My general approach was to check whether a local (non-prepared) transaction is still active in the NpgsqlPromotableSinglePhaseNotification when Close() is called. If so, we enter the "postponingClose" state instead of actually closing. Then, when the local transaction is terminated (because of a commit, rollback or promote) the connection is notified and does the real close. There are a few more tweaks (Dispose and reopen after close) but it should be pretty straightforward.

Note that this takes care of the pattern:
using (var conn1 = new NpgsqlConnection(...) {
conn1.Open(); conn1.Close();
conn1.Open(); conn1.Close();
}

But does not take care of the pattern:
using (var conn1 = new NpgsqlConnection(connString1) { ... }
using (var conn2 = new NpgsqlConnection(connString1) { ... }
As Josh suggested, since I think that would require handling stuff at the pool. Maybe a second commit?

Anyway, let me know what you think...

Note that there are also two tiny build cleanup commits before the real one...

Followup

No Followups Have Been Posted

Attached Files:

Changes:

No Changes Have Been Made to This Item

Powered By FusionForge