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

Handling activerecord statement invalid exception during sidekiq shutdow... #1354

Closed
wants to merge 1 commit into from

Conversation

rajofchennai
Copy link

I am not sure If this is the cleanest way to handle the issue.

Fix #897

@mperham
Copy link
Collaborator

mperham commented Nov 19, 2013

Sidekiq needs to be usable without Rails. You're referencing an ActiveRecord class which breaks that.

That said, I'm not sure there is a good answer for this.

@rajofchennai
Copy link
Author

I updated the change to make sure ActiveRecord is not a necessity.

@mperham
Copy link
Collaborator

mperham commented Nov 24, 2013

I really don't want to special case any one class, then someone else will want another class. With Ruby 2.1, we should be able to use Exception#cause generically to solve this problem.

@sentience
Copy link
Contributor

@mperham We’re wrestling with this as well. Would you welcome a pull request to fix this when Sidekiq is running on Ruby 2.1 (where Exception#cause is available)?

@mperham
Copy link
Collaborator

mperham commented Jun 27, 2014

Yes!

On Jun 26, 2014, at 23:47, Kevin Yank notifications@github.com wrote:

@mperham We’re wrestling with this as well. Would you welcome a pull request to fix this when Sidekiq is running on Ruby 2.1 (where Exception#cause is available)?


Reply to this email directly or view it on GitHub.

@sentience
Copy link
Contributor

Digging further, we’re skeptical that the ActiveRecord::StatementInvalid error that’s causing the job to be incorrectly duplicated on the Retry queue will have Sidekiq::Shutdown as its cause. Here’s what we’re seeing in our logs right now:

2014-06-27T05:08:47Z 7681 TID-ouo0lbxh0 INFO: Shutting down
2014-06-27T05:08:47Z 7681 TID-ouo1g1h34 INFO: Shutting down 9 quiet workers
2014-06-27T05:08:47Z 7681 TID-ouo1g1h34 INFO: Pausing up to 8 seconds to allow workers to finish...
2014-06-27T05:08:55Z 7681 TID-ouo1g1h34 WARN: Terminating 1 busy worker threads
2014-06-27T05:08:55Z 7681 TID-ouo1g1h34 WARN: Work still in progress [#<struct Sidekiq::BasicFetch::UnitOfWork queue="sidekiq:queue:default", message="{\"retry\":true,\"queue\":\"default\",\"class\":\"DoThingJob\",\"args\":[4990],\"jid\":\"bdf60096577828fd1982dd0c\",\"enqueued_at\":1403844700.9247384}">]
2014-06-27T05:08:55Z 7681 TID-ouo1g1h34 INFO: Pushed 1 messages back to Redis
2014-06-27T05:08:55Z 7681 TID-ouo0ly9mg DoThingJob JID-bdf60096577828fd1982dd0c INFO: fail: 308.087 sec
2014-06-27T05:08:55Z 7681 TID-ouo0ly9mg WARN: {"retry"=>true, "queue"=>"default", "class"=>"DoThingJob", "args"=>[4990], "jid"=>"bdf60096577828fd1982dd0c", "enqueued_at"=>1403844700.9247384, "error_message"=>"Mysql2::Error: closed MySQL connection: ROLLBACK", "error_class"=>"ActiveRecord::StatementInvalid", "failed_at"=>2014-06-27 05:08:55 UTC, "retry_count"=>0}
2014-06-27T05:08:55Z 7681 TID-ouo0ly9mg WARN: Mysql2::Error: closed MySQL connection: ROLLBACK
2014-06-27T05:08:55Z 7681 TID-ouo0ly9mg WARN: /srv/app/shared/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:301:in `query'

Nevertheless, we’ll give it a try and see if it helps.

sentience referenced this pull request in avalancheau/sidekiq Jun 27, 2014
…e retried.

Jobs in progress during a Sidekiq shutdown/restart are requeued for immediate execution. They should not also be queued for retry.

This is an attempt at a cleaner fix than that proposed with mperham#1354, also discussed on mperham#897. Because it depends on Exception#cause, this fix will only be effective on Ruby 2.1.0; however, the code will run on earlier Rubies.
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

Successfully merging this pull request may close these issues.

Sidekiq::Shutdown duplicates jobs after sidekiq:stop/sidekiq:start
3 participants