1

Before I begin, I'm in an environment that uses NHibernate with C#. We don't use the JavaScript implementation; just C# on the backend. We have a combination of ASP.NET 3.5 and .NET 3.5 in a Windows Service that spins off separate process threads.

Has anyone ever experienced an issue with NHibernate where an exception can cause other processes to break?

For example:

We have a Windows Service outside of our normal web application, which does a lot of data management and automated processes. Let's consider the following scenario:

=> Service A is populating a table with the word "Hello" into a column with the data type VARCHAR(5)

=> Service B is updating values on a separate table from the word "August" to "September" with the data type VARCHAR(50)

Service A is in a transaction that has all inserts happening in the same transaction.

Service B is in a transaction that has all updates happening in the same transaction.

Service A and Service B obviously don't share the same transaction.

These services are running in separate threads and execute at the same time.

If Service A tries to enter "Hello Again" and violates the data constraints, Service B will exit without finishing the process. There is usually a rollback will occur on Service A and Service B, due to this, so no changes are committed.

I apologize if this explanation is too cryptic, but the data and the process are irrelevant; it's the exception and results that are what are important. Almost all of our processes do it and the exeption that occurs could be just about anything, including data type mismatches, timeouts or database deadlocks.

This is all theory, so I don't have specific code that can be guaranteed to replicate this.

I guess what I'm getting at is if NHibernate will roll back other transactions because a separate thread had an exception within it?

Please also understand that the Windows Service is the easiest way for us to replicate this, but we have also seen this happen during the ASP.NET processes.

Thank you in advance for any and all help!

Derek
  • 133
  • 1
  • 9

1 Answers1

1

I have a system where multiple processes and services responsible for specific db actions (Updates and Inserts). The idea is that updates are actionable in "quiet" periods, usually at night. (report building...slow..)

is if NHibernate will roll back other transactions because a separate thread had an exception within it?

It depends how you programmed it. A problem we had before, was where connections were not closed properly. When a worker thread failed, these connections were waiting to be closed explicitly. So now the nhibernate session code bits are wrapped in a try / catch / finally thus making sure we clean up on exception. We can then roll back transactions on failure, and then retry again in a few seconds. I assume like my system, a lock on a database record may block another process on another service. On the other hand, if the main process dies, it is a different problem all together.

Dai Bok
  • 3,451
  • 2
  • 53
  • 70
  • 1
    its probably not the connection that has to be closed but the transaction that has to be rolled back properly. Otherwise the db server will wait for the transaction to finish (either commit or rollback), other waiting transactions might time out during that time. But you're right, this is depending on the way your code handles problems during a transaction. Always make sure to dispose of your transaction object (which triggers an implicit rollback). – Dirk Trilsbeek Mar 24 '15 at 08:47
  • True, I guess that is why the other services may be failing. you can set the transaction timeout in Nhibernate which might help test this scenario http://stackoverflow.com/questions/14709978/how-to-set-the-timeout-on-a-nhibernate-transaction – Dai Bok Mar 24 '15 at 09:09