views:

146

answers:

2

I've just come to a realization about deadlocks - namely what they are - and I'm concerned about this issue affecting my Rails code.

Are there any specific deadlock issues to watch out for while developing a Rails app?

Have you ever encountered a deadlock in your Rails code - or is that even possible?

(I'm not referring to database deadlocks - only application deadlocks).

+2  A: 

Deadlock implies competition for an I/O resource, which is why it comes up for databases most often. If you're improperly locking and requesting resources and you're explicitly using threads, then yeah you need to be concerned.

However, the specific steps to take to mitigate any issues are dependent on the type of I/O you are accessing.

Mike Buckbee
A: 

Rails doesn't have many OS level deadlock concerns since Ruby 1.8 is single threaded, and even in 1.9 is locked

The concerns are mainly in the database. Rails has a double whammy where ActiveRecord abstracts from the database AND stuff like FKs and constraints are pushed into application level validations (before_save, validates_*, etc) and the result discourages developers from thinking about DB deadlock situations.

If you're using MYSQl, you can read about problem areas with innodb (default in Rails) here http://dev.mysql.com/doc/refman/5.1/en/innodb-transaction-model.html

ambertch