Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>We've finally narrowed this down to a cause.</p> <p>When opening a session, if there is an ambient distributed transaction, NHibernate attaches an event handler to the Transaction.TransactionCompleted, which closes the session when the distributed transaction is completed. This appears to be subject to a race condition wherein the connection may be closed and returned to the pool before the deadlock error propagates across, leaving the connection in an unusable state.</p> <p>The following code will reproduce the error for us occasionally, even without any load on the server. If there is extreme load on the server, it becomes more consistent.</p> <pre><code>using(var scope = new TransactionScope()) { // // Force promotion to distributed transaction // TransactionInterop.GetTransmitterPropagationToken(Transaction.Current); var connection = new SqlConnection(_connectionString); connection.Open(); // // Close the connection once the distributed transaction is // completed. // Transaction.Current.TransactionCompleted += (sender, e) =&gt; connection.Close(); using(connection.BeginTransaction()) // // Deadlocks but sometimes does not raise exception // ForceDeadlockOnConnection(connection); scope.Complete(); } // // Subsequent attempts to open a connection with the same // connection string will fail // </code></pre> <p>We have not settled on a solution, but the following things will eliminate the problem (while possibly having other consequences):</p> <ul> <li>Turning off connection pooling</li> <li>Using NHibernate's <strong>AdoNetTransactionFactory</strong> instead of <strong>AdoNetWithDistributedTransactionFactory</strong></li> <li>Adding error handling that calls <strong>SqlConnection.ClearPool()</strong> when the "server failed to resume the transaction" error occurs</li> </ul> <p>According to Microsoft (https://connect.microsoft.com/VisualStudio/feedback/details/722659/), the SqlConnection class is not thread-safe, and that includes closing the connection on a separate thread. Based on this response we have filed a bug report for NHibernate (http://nhibernate.jira.com/browse/NH-3023).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload