Skip to content

Commit 82ded5d

Browse files
Chaining scopes with ODBC is bugged: disabling the test.
It may check the previous transaction during enlistment, without guarding against it being disposed.
1 parent d8c8f1c commit 82ded5d

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/NHibernate.Test/Async/SystemTransactions/SystemTransactionFixture.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using System.Threading;
1515
using System.Transactions;
1616
using NHibernate.Cfg;
17+
using NHibernate.Driver;
1718
using NHibernate.Engine;
1819
using NHibernate.Linq;
1920
using NHibernate.Test.TransactionTest;
@@ -186,6 +187,12 @@ public async Task CanDeleteItemAsync(bool explicitFlush)
186187
public async Task CanUseSessionWithManyScopesAsync(bool explicitFlush)
187188
{
188189
IgnoreIfUnsupported(explicitFlush);
190+
// ODBC with SQL-Server always causes scopes to go distributed, which causes their transaction completion to run
191+
// asynchronously. But ODBC enlistment also check the previous transaction in a way that do not guard against it
192+
// being concurrently disposed of. See https://github.com/nhibernate/nhibernate-core/pull/1505 for more details.
193+
Assume.That(!(Sfi.ConnectionProvider.Driver is OdbcDriver),
194+
"ODBC sometimes fails on second scope by checking the previous transaction status, which may yield an object disposed exception");
195+
189196
using (var s = WithOptions().ConnectionReleaseMode(ConnectionReleaseMode.OnClose).OpenSession())
190197
{
191198
using (var tx = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
@@ -529,4 +536,4 @@ public class SystemTransactionWithoutAutoJoinTransactionAsync : SystemTransactio
529536
{
530537
protected override bool AutoJoinTransaction => false;
531538
}
532-
}
539+
}

src/NHibernate.Test/SystemTransactions/SystemTransactionFixture.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Threading;
55
using System.Transactions;
66
using NHibernate.Cfg;
7+
using NHibernate.Driver;
78
using NHibernate.Engine;
89
using NHibernate.Linq;
910
using NHibernate.Test.TransactionTest;
@@ -175,6 +176,12 @@ public void CanDeleteItem(bool explicitFlush)
175176
public void CanUseSessionWithManyScopes(bool explicitFlush)
176177
{
177178
IgnoreIfUnsupported(explicitFlush);
179+
// ODBC with SQL-Server always causes scopes to go distributed, which causes their transaction completion to run
180+
// asynchronously. But ODBC enlistment also check the previous transaction in a way that do not guard against it
181+
// being concurrently disposed of. See https://github.com/nhibernate/nhibernate-core/pull/1505 for more details.
182+
Assume.That(!(Sfi.ConnectionProvider.Driver is OdbcDriver),
183+
"ODBC sometimes fails on second scope by checking the previous transaction status, which may yield an object disposed exception");
184+
178185
using (var s = WithOptions().ConnectionReleaseMode(ConnectionReleaseMode.OnClose).OpenSession())
179186
{
180187
using (var tx = new TransactionScope())
@@ -539,4 +546,4 @@ public void SessionIsNotEnlisted()
539546
}
540547
}
541548
}
542-
}
549+
}

0 commit comments

Comments
 (0)