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

Getting ActiveRecord::RecordNotFound from time to time when using Sidekiq #95

Open
Nowaker opened this issue Jun 23, 2016 · 6 comments
Open

Comments

@Nowaker
Copy link

Nowaker commented Jun 23, 2016

I can clearly see after_commit being used in the code:

          after_commit :send_devise_pending_notifications

Yet, ActiveRecord::RecordNotFound still happens from time to time.

Any ideas how to fix it, @mperham?

@mperham
Copy link

mperham commented Jun 23, 2016

I have no idea what the problem might be.

@KazW
Copy link

KazW commented Jun 27, 2016

I've seen this in production in a few apps, my best guess is that Sidekiq is picking up the job before the transaction has completed. Adding a delay of a few seconds has fixed it in every case I've come across.

@Nowaker
Copy link
Author

Nowaker commented Jun 27, 2016

@KazW The real question is how. We can clearly see after_commit block is used. That means Sidekiq is either faster than light, or after_commit doesn't happen after the commit.

@KazW
Copy link

KazW commented Jun 27, 2016

Ah, I've only used this with Devise 3.x when it was after_save... Nevermind!

@voltechs
Copy link

No resolution on this then? We're experiencing this with other Sidekiq jobs. Does anybody know of a way to simulate this in a test environment (we're specifically using Postgres)? We have some linear code that basically goes

some_model = SomeModel.create!(...)
SomeAsyncService.new.perform(some_model)

The service kicks off a Sidekiq Job, which picks up the job (impressively) before the model is committed (despite a proper primary key being set etc).

@Nowaker
Copy link
Author

Nowaker commented Feb 28, 2018

@voltechs No resolution, unfortunately. Given Sidekiq cannot be faster than light, after_commit must happen technically after a commit but before the result of that commit is available to database clients.

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

4 participants