File tree Expand file tree Collapse file tree 3 files changed +11
-13
lines changed Expand file tree Collapse file tree 3 files changed +11
-13
lines changed Original file line number Diff line number Diff line change @@ -243,8 +243,11 @@ public partial interface ISession : IDisposable
243
243
/// End the <c>ISession</c> by disconnecting from the ADO.NET connection and cleaning up.
244
244
/// </summary>
245
245
/// <remarks>
246
- /// It is not strictly necessary to <c>Close()</c> the <c>ISession</c> but you must
247
- /// at least <c>Disconnect()</c> it.
246
+ /// <para>It is not strictly necessary to <c>Close()</c> the <c>ISession</c> but you must
247
+ /// at least <c>Disconnect()</c> or <c>Dispose</c> it.</para>
248
+ /// <para>Do not call this method inside a transaction scope, use <c>Dispose</c> instead,
249
+ /// since <c>Close()</c> is not aware of system transactions: if the transaction completion
250
+ /// requires the session, it will fail.</para>
248
251
/// </remarks>
249
252
/// <returns>The connection provided by the application or <see langword="null" /></returns>
250
253
DbConnection Close ( ) ;
Original file line number Diff line number Diff line change @@ -264,16 +264,10 @@ public bool ShouldAutoClose
264
264
get { return IsAutoCloseSessionEnabled && ! IsClosed ; }
265
265
}
266
266
267
- /// <summary>
268
- /// Close the session and release all resources
269
- /// <remarks>
270
- /// Do not call this method inside a transaction scope, use <c>Dispose</c> instead, since
271
- /// Close() is not aware of distributed transactions
272
- /// </remarks>
273
- /// </summary>
267
+ /// <inheritdoc />
274
268
public DbConnection Close ( )
275
269
{
276
- using ( BeginContext ( ) )
270
+ using ( BeginProcess ( true ) )
277
271
{
278
272
log . Debug ( "closing session" ) ;
279
273
if ( IsClosed )
@@ -1498,7 +1492,8 @@ public void Dispose()
1498
1492
// a local variable for avoiding it, but that would turn a failure causing an exception
1499
1493
// into a failure causing a session and connection leak. So do not do it, better blow away
1500
1494
// with a null ref rather than silently leaking a session. And then fix the synchronization.
1501
- if ( TransactionContext != null && TransactionContext . CanFlushOnSystemTransactionCompleted )
1495
+ if ( TransactionContext != null && TransactionContext . CanFlushOnSystemTransactionCompleted &&
1496
+ TransactionContext . IsInActiveTransaction )
1502
1497
{
1503
1498
TransactionContext . ShouldCloseSessionOnSystemTransactionCompleted = true ;
1504
1499
return ;
Original file line number Diff line number Diff line change @@ -299,8 +299,8 @@ protected virtual void Lock()
299
299
{
300
300
if ( ! _needCompletionLocking || _isDisposed )
301
301
return ;
302
- _needCompletionLocking = false ;
303
302
_lock . Reset ( ) ;
303
+ _needCompletionLocking = false ;
304
304
}
305
305
306
306
/// <summary>
@@ -583,7 +583,7 @@ private static void Cleanup(ISessionImplementor session)
583
583
foreach ( var dependentSession in session . ConnectionManager . DependentSessions . ToList ( ) )
584
584
{
585
585
var dependentContext = dependentSession . TransactionContext ;
586
- // Do not nullify TransactionContext here, could create a race condition with
586
+ // Do not nullify TransactionContext here, it could create a race condition with
587
587
// would be await-er on session for disposal (test cases cleanup checks by example).
588
588
if ( dependentContext == null )
589
589
continue ;
You can’t perform that action at this time.
0 commit comments