rails/rails — pull request #13656 by chanks (2014-01-09 23:35:47+00:00)
Title: Data corruption risk: Roll back open transactions when the running thread is killed.

This is a fix for this issue:

http://coderrr.wordpress.com/2011/05/03/beware-of-threadkill-or-your-activerecord-transactions-are-in-danger-of-being-partially-committed/

In a nutshell: When the Ruby process exits, Thread#kill is used to end all threads that are still running (aside from the main one). Thread#kill runs ensure blocks but not rescue blocks, which means that if one of those threads is in the middle of a transaction, it will be prematurely committed rather than rolled back, which is bad bad news.

Luckily, Ruby 2.0+ sets a thread's status to "aborting" when it is killed, so it's a simple fix to check for it in the ensure block. The problem is not fixable on Ruby 1.9, so the spec doesn't run there.