How many bugs can a single assumption cause?

time to read 2 min | 270 words

NH Prof make some assumptions about the way you use NHibernate. In particular, it assumes that you are using it in a best practice way and will warn you if you deviate from that.

I just got a bug report in which NH Prof was reporting a cross threaded session usage when no such thing actually happened. Once I got the dump, I took one look at the actual data and immediately know what was going on there.

It looked like this:


And I went Duh! We have a distributed transaction here, and the commit is actually happening on another thread! This is a scenario where multi threaded usage of the session is safe, since we know that there can be no concurrent access to it.

But there are actually 3 different bugs related to this tiny assumption:

  • Allowing multi threaded operations without warning when in DTC transactions – That is the original bug that I discovered.
  • A single session spanning multiple threads – which meant that I had to improve my session finding algorithm to also include this into account. Otherwise we would get the commit statement on its own session.
  • A session closing without committing or rolling back a DTC is fine and should not generate the abandoned transaction warning.

Luckily, writing tests for NH Prof is a pleasure, and it took very little time to fix all of them.