Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mysql2::Error: Deadlock found when trying to get lock; try restarting transaction: #277

Closed
joshrendek opened this issue Aug 8, 2011 · 7 comments

Comments

@joshrendek
Copy link

Any ideas on where to find this in the source or how to patch it/fix it?

I'm getting this when running 15 workers, 2 are deadlocking on the same job:
Mysql2::Error: Deadlock found when trying to get lock; try restarting transaction: UPDATE delayed_jobs SET locked_at = '2011-08-08 21:30:10', locked_by = 'delayed_job.10 host:226237 pid:27929' WHERE ((run_at <= '2011-08-08 21:30:10' AND (locked_at IS NULL OR locked_at < '2011-08-08 21:15:10') OR locked_by = 'delayed_job.10 host:226237 pid:27929') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1

Mysql2::Error: Deadlock found when trying to get lock; try restarting transaction: UPDATE delayed_jobs SET locked_at = '2011-08-08 21:30:10', locked_by = 'delayed_job.0 host:226237 pid:27869' WHERE ((run_at <= '2011-08-08 21:30:10' AND (locked_at IS NULL OR locked_at < '2011-08-08 21:15:10') OR locked_by = 'delayed_job.0 host:226237 pid:27869') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1

This is causing the job workers to die.

@betamatt
Copy link
Collaborator

betamatt commented Aug 8, 2011

What version of delayed_job is this? Looks like 2.1.3, which is broken. Have
you tried the latest gem?

On Mon, Aug 8, 2011 at 5:43 PM, bluescripts <
[email protected]>wrote:

Any ideas on where to find this in the source or how to patch it/fix it?

I'm getting this when running 15 workers, 2 are deadlocking on the same
job:
Mysql2::Error: Deadlock found when trying to get lock; try restarting
transaction: UPDATE delayed_jobs SET locked_at = '2011-08-08 21:30:10',
locked_by = 'delayed_job.10 host:226237 pid:27929' WHERE ((run_at <=
'2011-08-08 21:30:10' AND (locked_at IS NULL OR locked_at < '2011-08-08
21:15:10') OR locked_by = 'delayed_job.10 host:226237 pid:27929') AND
failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1

Mysql2::Error: Deadlock found when trying to get lock; try restarting
transaction: UPDATE delayed_jobs SET locked_at = '2011-08-08 21:30:10',
locked_by = 'delayed_job.0 host:226237 pid:27869' WHERE ((run_at <=
'2011-08-08 21:30:10' AND (locked_at IS NULL OR locked_at < '2011-08-08
21:15:10') OR locked_by = 'delayed_job.0 host:226237 pid:27869') AND
failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1

This is causing the job workers to die.

Reply to this email directly or view it on GitHub:
#277

@joshrendek
Copy link
Author

Was using 2.1.2 -- will try upgrading and let you know.

@joshrendek
Copy link
Author

Fixed :) thanks!

@jamsi
Copy link

jamsi commented Apr 22, 2013

I'm seeing this same issue with 6 workers using the following gems;

delayed_job (3.0.5)
  activesupport (~> 3.0)
delayed_job_active_record (0.4.4)
  activerecord (>= 2.1.0, < 4)
  delayed_job (~> 3.0)

This is the error;

2013-04-22T14:29:11+1000: [Worker(delayed_job.2 host:marvin pid:7248)] Class#notification failed with ActiveRecord::StatementInvalid: Mysql2::Error: Deadlock found when trying to get lock; try restarting transaction: DELETE FROM `delayed_jobs` WHERE `delayed_jobs`.`id` = 170209 - 0 failed attempts

This error is causing workers to die.

@chamnap
Copy link

chamnap commented Apr 29, 2013

This happens to me as well. How to fix this?

@donaldpiret
Copy link

Same issue here

@gorism
Copy link

gorism commented Jun 5, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants