sebbacon/alaveteli — Issue #336: Database deadlock triggered by incoming mail
Author: robinhouston
Created: 2012-01-11 12:24:39+00:00
State: open

We have occasional deadlock errors from `script/mailin`, like this:

/data/vhost/www.whatdotheyknow.com/alaveteli/vendor/rails/railties/lib/commands/runner.rb:48: /data/vhost/www.whatdotheyknow.com/alaveteli/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:227:in `log': PGError: ERROR: deadlock detected (ActiveRecord::StatementInvalid)
DETAIL: Process 13369 waits for ShareLock on transaction 15656225; blocked by process 13372.
Process 13372 waits for ExclusiveLock on tuple (2885,27) of relation 16462 of database 16385; blocked by process 13369.
HINT: See server log for query details.
: UPDATE "info_requests" SET "updated_at" = '2012-01-11 12:17:09.609519', "awaiting_description" = 't' WHERE "id" = 100022
from /data/vhost/www.whatdotheyknow.com/alaveteli/vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:520:in `execute'
from /data/vhost/www.whatdotheyknow.com/alaveteli/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:265:in `update_sql'
from /data/vhost/www.whatdotheyknow.com/alaveteli/vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:531:in `update_sql'
from /data/vhost/www.whatdotheyknow.com/alaveteli/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:49:in `update_without_query_dirty'
from /data/vhost/www.whatdotheyknow.com/alaveteli/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:19:in `update'
from /data/vhost/www.whatdotheyknow.com/alaveteli/vendor/rails/activerecord/lib/active_record/base.rb:2936:in `update_without_lock'
from /data/vhost/www.whatdotheyknow.com/alaveteli/vendor/rails/activerecord/lib/active_record/locking/optimistic.rb:81:in `update_without_dirty'
from /data/vhost/www.whatdotheyknow.com/alaveteli/vendor/rails/activerecord/lib/active_record/dirty.rb:146:in `update_without_timestamps'
from /data/vhost/www.whatdotheyknow.com/alaveteli/vendor/rails/activerecord/lib/active_record/timestamp.rb:64:in `update_without_callbacks'
from /data/vhost/www.whatdotheyknow.com/alaveteli/vendor/rails/activerecord/lib/active_record/callbacks.rb:282:in `update'
from /data/vhost/www.whatdotheyknow.com/alaveteli/vendor/rails/activerecord/lib/active_record/base.rb:2927:in `create_or_update_without_callbacks'
from /data/vhost/www.whatdotheyknow.com/alaveteli/vendor/rails/activerecord/lib/active_record/callbacks.rb:250:in `create_or_update'
from /data/vhost/www.whatdotheyknow.com/alaveteli/vendor/rails/activerecord/lib/active_record/base.rb:2594:in `save_without_validation!'
from /data/vhost/www.whatdotheyknow.com/alaveteli/vendor/rails/activerecord/lib/active_record/validations.rb:1099:in `save_without_dirty!'
from /data/vhost/www.whatdotheyknow.com/alaveteli/vendor/rails/activerecord/lib/active_record/dirty.rb:87:in `save_without_transactions!'
from /data/vhost/www.whatdotheyknow.com/alaveteli/vendor/rails/activerecord/lib/active_record/transactions.rb:200:in `save!'
from /data/vhost/www.whatdotheyknow.com/alaveteli/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in `transaction'
from /data/vhost/www.whatdotheyknow.com/alaveteli/vendor/rails/activerecord/lib/active_record/transactions.rb:182:in `transaction'
from /data/vhost/www.whatdotheyknow.com/alaveteli/vendor/rails/activerecord/lib/active_record/transactions.rb:200:in `save!'
from /data/vhost/www.whatdotheyknow.com/alaveteli/vendor/rails/activerecord/lib/active_record/transactions.rb:208:in `rollback_active_record_state!'
from /data/vhost/www.whatdotheyknow.com/alaveteli/vendor/rails/activerecord/lib/active_record/transactions.rb:200:in `save!'
from /data/vhost/www.whatdotheyknow.com/alaveteli/app/models/info_request.rb:447:in `receive'
from /data/vhost/www.whatdotheyknow.com/alaveteli/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in `transaction'
from /data/vhost/www.whatdotheyknow.com/alaveteli/vendor/rails/activerecord/lib/active_record/transactions.rb:182:in `transaction'
from /data/vhost/www.whatdotheyknow.com/alaveteli/app/models/info_request.rb:433:in `receive'
from /data/vhost/www.whatdotheyknow.com/alaveteli/app/models/request_mailer.rb:233:in `receive'
from /data/vhost/www.whatdotheyknow.com/alaveteli/app/models/request_mailer.rb:226:in `each'
from /data/vhost/www.whatdotheyknow.com/alaveteli/app/models/request_mailer.rb:226:in `receive'
from /data/vhost/www.whatdotheyknow.com/alaveteli/app/models/request_mailer.rb:198:in `receive'
from (eval):1
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `eval'
from /data/vhost/www.whatdotheyknow.com/alaveteli/vendor/rails/railties/lib/commands/runner.rb:48
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
from script/runner:38
from script/runner:8:in `chdir'
from script/runner:8