Skip to content

Commit 06013ad

Browse files
Revert "The crutch has to come back"
This reverts commit 78639a6.
1 parent 78639a6 commit 06013ad

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

src/NHibernate/Transaction/AdoNetWithSystemTransactionFactory.cs

+7-15
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,7 @@ public class SystemTransactionContext : ITransactionContext, IEnlistmentNotifica
187187
/// </summary>
188188
protected internal System.Transactions.Transaction EnlistedTransaction { get; }
189189
/// <inheritdoc />
190-
public bool ShouldCloseSessionOnSystemTransactionCompleted
191-
{
192-
get => _shouldCloseSessionOnSystemTransactionCompleted;
193-
set => _shouldCloseSessionOnSystemTransactionCompleted = value;
194-
}
190+
public bool ShouldCloseSessionOnSystemTransactionCompleted { get; set; }
195191
/// <inheritdoc />
196192
public bool IsInActiveTransaction { get; protected set; } = true;
197193
/// <inheritdoc />
@@ -203,7 +199,6 @@ public bool ShouldCloseSessionOnSystemTransactionCompleted
203199
private readonly System.Transactions.Transaction _originalTransaction;
204200
private readonly ManualResetEventSlim _lock = new ManualResetEventSlim(true);
205201
private volatile bool _needCompletionLocking = true;
206-
private volatile bool _shouldCloseSessionOnSystemTransactionCompleted;
207202
private bool _preparing;
208203
// Required for not locking the completion phase itself when locking session usages from concurrent threads.
209204
private static readonly AsyncLocal<bool> _bypassLock = new AsyncLocal<bool>();
@@ -493,15 +488,12 @@ protected virtual void CompleteTransaction(bool isCommitted)
493488
// In case of a rollback due to a timeout, we may have the session disposal running concurrently
494489
// to the transaction completion in a way our current locking mechanism cannot fully protect: the
495490
// session disposal "BeginProcess" can go through the Wait before it is locked but flag the
496-
// session as processing after the transaction completion has read it as not processing. This may
497-
// then cause concurrency issues in the case the transaction context has to close the session
498-
// instead of the session disposal. To dodge that unlikely case occuring witb a legacy behavior
499-
// we advise to disable, we consider, when the legacy behavior is used, that the session is still
500-
// processing initially regardless of its actual status in case of rollback. That is a crutch,
501-
// relying on Thread.Sleep() to dodge the possible concurrency issue. If users do not want to rely
502-
// on such crutch, they should disable the commit on system transaction completion setting
503-
// (transaction.use_connection_on_system_prepare).
504-
var isSessionProcessing = !isCommitted && _useConnectionOnSystemTransactionPrepare || _session.IsProcessing();
491+
// session as processing after the transaction completion has read it as not processing. To dodge
492+
// that very unlikely case, we could consider the session as still processing initially regardless
493+
// of its actual status in case of rollback by changing below condition to
494+
// "!isCommitted || _session.IsProcessing()". That would cause a Thread.Sleep in all rollback cases.
495+
// That would reinforce the impracticality of that concurrency possibility, but with an ugly crutch.
496+
var isSessionProcessing = _session.IsProcessing();
505497
try
506498
{
507499
// Allow transaction completed actions to run while others stay blocked.

0 commit comments

Comments
 (0)