Worker reads outdated data from db

19 views
Skip to first unread message

Chris Kopsidas

unread,
Jul 6, 2017, 9:23:57 AM7/6/17
to Sidekiq
Hello,

I create a worker from a callback which is triggered when a specific field of my model is set to true. The worker starts as expected.

It performs its task and continually checks if this field is true or false. Based on this field value it continues its task (if it is true) or exits (if it is false).

But even when this field for the monitored object is changed on db (I validate this via psql cmd line) the worker still reads the old value! It never reads the new value no matter how much time passes, so it never exits. Is this a caching issue? Something else?

Mike Perham

unread,
Jul 6, 2017, 10:26:48 AM7/6/17
to sid...@googlegroups.com
Do you see the same behavior in Rails console?

--
You received this message because you are subscribed to the Google Groups "Sidekiq" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sidekiq+unsubscribe@googlegroups.com.
To post to this group, send email to sid...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sidekiq/3bf44751-d8a5-4fc0-b735-07b7a620974a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Mike Perham – CEO, Contributed Systems
Smart, effective open source infrastructure for your apps.

Chris Kopsidas

unread,
Jul 6, 2017, 1:55:52 PM7/6/17
to sid...@googlegroups.com
In rails console the specific entry is also false, as it should be. I use "after_save" call back to trigger the worker, the same issue appeared also with "before_save". The worker is triggered using "perform_async". It is like the worker has its own db snapshot :|

Does sidekiq use any caching or other mechanism that might be blocking it reading from disk? Maybe any related configuration?

Virus-free. www.avg.com

--
You received this message because you are subscribed to a topic in the Google Groups "Sidekiq" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sidekiq/tnMz-DeSHVg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sidekiq+unsubscribe@googlegroups.com.

To post to this group, send email to sid...@googlegroups.com.

Mike Perham

unread,
Jul 6, 2017, 2:01:14 PM7/6/17
to sid...@googlegroups.com
Could you try after_commit instead of after_save?  It’s possible Sidekiq is checking the database before the transaction has committed.



For more options, visit https://groups.google.com/d/optout.

Chris Kopsidas

unread,
Jul 6, 2017, 2:25:35 PM7/6/17
to sid...@googlegroups.com
I did the change and restarted both sidekiq and rails server. Unfortunately same behavior with this callback too.

Mike Perham

unread,
Jul 6, 2017, 2:38:39 PM7/6/17
to sid...@googlegroups.com
Do you see the same behavior if you make the change in one Rails console and read in another Rails console?


For more options, visit https://groups.google.com/d/optout.

Chris Kopsidas

unread,
Jul 6, 2017, 6:51:39 PM7/6/17
to sid...@googlegroups.com
No, when I save the object I can immediately see the change in the second rails console which was already spawned.. Sidekiq worker does not get the new value when the change is done via console too. I don't know if it somehow affects the framework behavior but I am using rail_admin to perform the changes. But I only face this issue concerning sidekiq worker, everything else seems to be updated normally.

Mike Perham

unread,
Jul 6, 2017, 6:54:51 PM7/6/17
to sid...@googlegroups.com
I can’t explain that then.  Part of Sidekiq’s ethos is that it never touches your database or any ActiveRecord code at all.  It boots Rails and uses the ActiveSupport::Executor API to run your job code, that’s it.


For more options, visit https://groups.google.com/d/optout.

Chris Kopsidas

unread,
Jul 6, 2017, 7:09:57 PM7/6/17
to sid...@googlegroups.com
Hmm, ok, thank you for your time and support. So there is not a scenario where sidekiq gets the model as is in memory and accesses this instead of the disk?

Mike Perham

unread,
Jul 6, 2017, 7:12:15 PM7/6/17
to sid...@googlegroups.com
Sidekiq doesn’t do anything but execute your perform method.  It has no idea how your Rails app and ActiveRecord are configured, esp wrt caching.


For more options, visit https://groups.google.com/d/optout.

Chris Kopsidas

unread,
Jul 6, 2017, 7:14:39 PM7/6/17
to sid...@googlegroups.com
Thank you again! I will try to debug it, I will come up with something hopefully.

jo...@symdistro.com

unread,
Oct 16, 2017, 11:47:57 AM10/16/17
to Sidekiq
Hey Chris, did you get this worked out? The wiki's trouble shooting page suggests using more precise caching with config.active_record.cache_timestamp_format = :nsec.


To unsubscribe from this group and stop receiving emails from it, send an email to sidekiq+u...@googlegroups.com.

To post to this group, send email to sid...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sidekiq/3bf44751-d8a5-4fc0-b735-07b7a620974a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Mike Perham – CEO, Contributed Systems
Smart, effective open source infrastructure for your apps.

--
You received this message because you are subscribed to a topic in the Google Groups "Sidekiq" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sidekiq/tnMz-DeSHVg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sidekiq+u...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Sidekiq" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sidekiq+u...@googlegroups.com.

To post to this group, send email to sid...@googlegroups.com.



--
Mike Perham – CEO, Contributed Systems
Smart, effective open source infrastructure for your apps.

--
You received this message because you are subscribed to a topic in the Google Groups "Sidekiq" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sidekiq/tnMz-DeSHVg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sidekiq+u...@googlegroups.com.

To post to this group, send email to sid...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Sidekiq" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sidekiq+u...@googlegroups.com.

To post to this group, send email to sid...@googlegroups.com.



--
Mike Perham – CEO, Contributed Systems
Smart, effective open source infrastructure for your apps.

--
You received this message because you are subscribed to a topic in the Google Groups "Sidekiq" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sidekiq/tnMz-DeSHVg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sidekiq+u...@googlegroups.com.

To post to this group, send email to sid...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Sidekiq" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sidekiq+u...@googlegroups.com.

To post to this group, send email to sid...@googlegroups.com.



--
Mike Perham – CEO, Contributed Systems
Smart, effective open source infrastructure for your apps.

--
You received this message because you are subscribed to a topic in the Google Groups "Sidekiq" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sidekiq/tnMz-DeSHVg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sidekiq+u...@googlegroups.com.

To post to this group, send email to sid...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Sidekiq" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sidekiq+u...@googlegroups.com.

To post to this group, send email to sid...@googlegroups.com.



--
Mike Perham – CEO, Contributed Systems
Smart, effective open source infrastructure for your apps.

--
You received this message because you are subscribed to a topic in the Google Groups "Sidekiq" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sidekiq/tnMz-DeSHVg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sidekiq+u...@googlegroups.com.

Chris Kopsidas

unread,
Oct 19, 2017, 8:34:21 AM10/19/17
to Sidekiq
Hello,

Thanks for the interest. We decided to implement a completely different approach for our service so we did not have to use this mechanism at all.

Phan Anh Le

unread,
Feb 9, 2018, 12:46:19 PM2/9/18
to Sidekiq
One of the potential culprits is that if the check is a loop within an open transaction then it might not see the update if the isolation level is repeatable-read.
Reply all
Reply to author
Forward
0 new messages