Skip to content

Commit d864dbe

Browse files
NH-2176 - on session disposal, release connection as soon as possible.
1 parent 42af102 commit d864dbe

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/NHibernate/AdoNet/ConnectionManager.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,12 @@ public void EnlistIfRequired()
383383
private bool RequireConnectionSwapInDtc
384384
=> _ownConnection && Factory.Dialect.SupportsConcurrentWritingConnectionsInSameTransaction;
385385

386+
public void ReleaseConnectionIfUneededForDtc()
387+
{
388+
if (RequireConnectionSwapInDtc)
389+
DisconnectOwnConnection();
390+
}
391+
386392
public IDisposable FlushingFromDtcTransaction
387393
{
388394
get

src/NHibernate/Transaction/AdoNetWithDistributedTransactionFactory.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,19 @@ public void ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork wo
7373
public class DistributedTransactionContext : ITransactionContext, IEnlistmentNotification
7474
{
7575
public System.Transactions.Transaction AmbientTransation { get; set; }
76-
public bool ShouldCloseSessionOnDistributedTransactionCompleted { get; set; }
7776

77+
public bool ShouldCloseSessionOnDistributedTransactionCompleted
78+
{
79+
get { return _shouldCloseSessionOnDistributedTransactionCompleted; }
80+
set
81+
{
82+
_shouldCloseSessionOnDistributedTransactionCompleted = value;
83+
if (value)
84+
_sessionImplementor.ConnectionManager.ReleaseConnectionIfUneededForDtc();
85+
}
86+
}
87+
88+
private bool _shouldCloseSessionOnDistributedTransactionCompleted;
7889
private readonly ISessionImplementor _sessionImplementor;
7990
private readonly ManualResetEvent _waitEvent = new ManualResetEvent(true);
8091
private readonly AsyncLocal<bool> _bypassWait = new AsyncLocal<bool>();

0 commit comments

Comments
 (0)