Skip to content

Instantly share code, notes, and snippets.

@andreasohlund
Created August 8, 2013 08:54
Show Gist options
  • Select an option

  • Save andreasohlund/6182903 to your computer and use it in GitHub Desktop.

Select an option

Save andreasohlund/6182903 to your computer and use it in GitHub Desktop.
NH bug workaround
void IManageUnitsOfWork.End(Exception ex)
{
if (SessionFactory == null || currentSession == null) return;
if (ex != null)
{
Transaction.Current.Rollback(ex);
while (Transaction.Current.TransactionInformation.Status != TransactionStatus.Aborted)
{
Thread.SpinWait(20);
}
}
using (currentSession)
using (currentSession.Transaction)
{
if (!currentSession.Transaction.IsActive)
return;
if (ex != null)
{
// Due to a race condition in NH3.3, explicit rollback can cause exceptions and corrupt the connection pool.
// Especially if there are more than one NH session taking part in the DTC transaction
currentSession.Transaction.Rollback();
}
else
currentSession.Transaction.Commit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment