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

[QUESTION] Regular errors with cache in Sidekiq jobs #256

Open
Floppy opened this issue Nov 8, 2024 · 1 comment
Open

[QUESTION] Regular errors with cache in Sidekiq jobs #256

Floppy opened this issue Nov 8, 2024 · 1 comment

Comments

@Floppy
Copy link

Floppy commented Nov 8, 2024

In my Sidekiq jobs, I get a lot of these failures:

Errno::ENOENT: No such file or directory @ rb_file_s_rename - (/usr/src/app/tmp/cache/.rails-settings-cached2Fv120241107-214-skp40x, /usr/src/app/tmp/cache/983/850/rails-settings-cached%2Fv1)

I assume this is because of multiple workers accessing the file at once, renaming it, etc. I'm clearing the cache before each job to make sure the jobs don't use stale settings from the main app, which is think might be causing a race condition where one worker has cleared the cache being used by another one.

  before_perform do |job|
    SiteSettings.clear_cache
  end

Is there a way to make the workers use separate cache files? They shouldn't really be removing something used by a different one.

Unfortunately I don't get a useful backtrace to identify exactly where it's happening. Has anyone seen this and solved it, or am I doing something unique and weird?

@Floppy
Copy link
Author

Floppy commented Nov 8, 2024

Some possible approaches:

  1. Use a dynamic cache key generated randomly per process, like Mastodon: https://github.com/mastodon/mastodon/blob/bde0f1239ab016a6dfc8229ba579c5e2cf96a8e6/app/models/setting.rb#L75
  2. Disable cache for sidekiq workers (not sure if this is possible)
  3. Use a different cache store for sidekiq workers, like a pure memory store so there's no disk race condition; each process would inherently get its own cache then as well.

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

1 participant