Issue Details (XML | Word | Printable)

Key: DNET-793
Type: Bug Bug
Status: Open Open
Priority: Minor Minor
Assignee: Jiri Cincura
Reporter: Frédéric Delaporte
Votes: 0
Watchers: 0

If you were logged in you would be able to see more operations.
.NET Data provider

Pool should not yield a connection with an ongoing transaction

Created: 24/Oct/17 03:31 PM   Updated: 24/Oct/17 03:33 PM
Component/s: ADO.NET Provider
Affects Version/s:
Fix Version/s: None

Environment: Windows 10 64bit, local Firebird server

 Description  « Hide
In distributed transaction cases, the transaction completion occurs asynchronously and concurrently to code following the transaction scope disposal.

In such case, it is possible to release the connection to the pool while its transaction is still ongoing, without having any clue about that. And requesting a connection from pool may then yield a connection still having an ongoing transaction.
Trying to begin a new transaction on it then fails with error: System.InvalidOperationException : A transaction is currently active. Parallel transactions are not supported.

Granted, that is a wicked case.

See discussion with a Microsoft employee: when distributed, MSDTC considers a transaction to be committed once it has collected all participant votes for committing from prepare phase. It then immediately notifies all participants of the outcome. This causes TransactionScope.Dispose to leave while the second phase of participants may still be executing. This means the transaction from the db view point can still be pending and not yet committed after the scope disposal. This is by design of MSDTC and we have to cope with that.
Some data provider may have a global locking mechanism causing any subsequent connection use to wait for the end of the commit phase, but this is not a general case. Such a mechanism has been put in place for NHibernate own volatile resource, but this only guarantee us that this NHibernate resource has ended its processing, it does not guarantee us that is the case of the Firebird one.

This causes a number of NHibernate tests to fail with Firebird regularly but not consistently.

A test case pattern for this would likely be like the [DistributedRollback|] test of Npgsql. There are more wicked cases involving distributed transaction in this test file, it may be worth checking them with Firebird too.
(For information, Npgsql checks distributed transaction status on connection when closed for avoiding returning them to pool if the transaction is not ended, something like just flagging them as having to return to pool once their transaction completion event finally gets executed. This avoid at least the pool trouble but not some other issues like trying to reuse the same connection immediately after a distributed scope disposal.)

 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Frédéric Delaporte added a comment - 24/Oct/17 03:33 PM
It was indeed tested with 6.0.0-Alpha2 version of Firebird .Net Data provider.