@@ -398,32 +398,40 @@ protected virtual void Dispose(bool dispose)
398398 return ;
399399 }
400400
401- ENSURE ( _state != TransactionState . Disposed , "transaction must be active before call Done" ) ;
402-
403- // clean snapshots if there is no commit/rollback
404- if ( _state == TransactionState . Active && _snapshots . Count > 0 )
401+ try
405402 {
406- // release writable snapshots
407- foreach ( var snapshot in _snapshots . Values . Where ( x => x . Mode == LockMode . Write ) )
408- {
409- // discard all dirty pages
410- _disk . DiscardDirtyPages ( snapshot . GetWritablePages ( true , true ) . Select ( x => x . Buffer ) ) ;
411403
412- // discard all clean pages
413- _disk . DiscardCleanPages ( snapshot . GetWritablePages ( false , true ) . Select ( x => x . Buffer ) ) ;
414- }
404+ ENSURE ( _state != TransactionState . Disposed , "transaction must be active before call Done" ) ;
415405
416- // release buffers in read-only snaphosts
417- foreach ( var snapshot in _snapshots . Values . Where ( x => x . Mode == LockMode . Read ) )
406+ // clean snapshots if there is no commit/rollback
407+ if ( _state == TransactionState . Active && _snapshots . Count > 0 )
418408 {
419- foreach ( var page in snapshot . LocalPages )
409+ // release writable snapshots
410+ foreach ( var snapshot in _snapshots . Values . Where ( x => x . Mode == LockMode . Write ) )
420411 {
421- page . Buffer . Release ( ) ;
412+ // discard all dirty pages
413+ _disk . DiscardDirtyPages ( snapshot . GetWritablePages ( true , true ) . Select ( x => x . Buffer ) ) ;
414+
415+ // discard all clean pages
416+ _disk . DiscardCleanPages ( snapshot . GetWritablePages ( false , true ) . Select ( x => x . Buffer ) ) ;
422417 }
423418
424- snapshot . CollectionPage ? . Buffer . Release ( ) ;
419+ // release buffers in read-only snaphosts
420+ foreach ( var snapshot in _snapshots . Values . Where ( x => x . Mode == LockMode . Read ) )
421+ {
422+ foreach ( var page in snapshot . LocalPages )
423+ {
424+ page . Buffer . Release ( ) ;
425+ }
426+
427+ snapshot . CollectionPage ? . Buffer . Release ( ) ;
428+ }
425429 }
426430 }
431+ catch ( Exception ex )
432+ {
433+ LOG ( $ "Error while disposing TransactionService: { ex . Message } ", "ERROR" ) ;
434+ }
427435
428436 _reader . Dispose ( ) ;
429437
0 commit comments