-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Sidekiq error Uninitialized Constant #789
Comments
Add a |
Hi @bensie This seems terribly impractical. Lock is used in more classes than this. Additionally this is not a unique error. We're getting the for a variety of libraries. My impression was that adding the lib folder under autoload should have fixed it but we're finding out that's not the case. |
Autoload itself as well as a number of libraries out there are not thread-safe. You need to ensure that all your code is eager loaded. |
Do you know why it would not happen all the time? It seems to happen 1:100 or jobs. This are all very common jobs that use the same functions most of the time, so I'd suspect we'd be getting more errors coming in if the threads were colliding. Is there anything we can do to fix it besides the eager loading? Is there a like a global solution for this? Having to require every single library needed for a class seems to defeat some of the purpose to Rails. |
Use |
@mperham the but issues is again that it's not a practical solution, since it would mean we'd need to eager load for each class all the dependencies. If autoload is not safe, is there another way to load the entire dependency tree safely? Edit: |
Ruby requires eager loading when using threads because require itself is not thread-safe. You can try adding lib to the config.eager_load_paths. |
From the docs, it looks like this will be safe on production.
But you sound a bit concern of using it. Are there any reservations to using this on a production environment? Cached classes are enabled for production by default on rails for production environments, so we should be able to use this. Edit: Also, require_dependency is recommended mostly for development. What are you thought about using that on prod? |
Typically lib has a lot of junk in it, things like Rake tasks in lib/tasks that dont need to be loaded in your app. But you can judge for yourself if it's worth it. |
I've got eager loading for lib set in application.rb
and am still getting this same error for classes that once worked. Now all of them give me the Uninitialized Constant error in development. Rails 3.2.13 Trace: MacBookPro:adminHeroku alexd$ env WORKER_PROCESS=1 bundle exec sidekiq -c 1 -r './config/boot.rb' - e worker |
The more I read about it, the more I realize Rails is just not thread In our application it was pretty impossible to do what James Miller Basically individually requiring the classes you need for each task. The above fix worked on our project though we limited it to only eager_load Did you make sure it's on the application.rb? or at least in the Juan Delgado On Wed, May 29, 2013 at 6:00 AM, kakubei notifications@github.com wrote:
|
@juand Rails is thread-safe. Autoloading is not. Use |
@mperham thanks for correcting me. Isn't Autoloading a basic configuration I think that with Rails even though it does support thread safety, it's This was my first time delving into multi-threading so I do apologize if |
Yep, unfortunately autoloading doesn't work well except for code in |
I'm a little confused here, I don't think the issue I'm seeing is due to lack of a require_dependency, I believe it's something else since the same setup works on Heroku and even locally in Development in the Padrino Console the classes that Sidekiq is complaining about are recognized properly. Just when I try to run a job locally I get these errors. Not really sure where the problem is, any help would be appreciated. Thanks. |
@kakubei, isn't it because by default, in http://guides.rubyonrails.org/v3.2.13/configuring.html#rails-general-configuration config.eager_load_paths accepts an array of paths from which Rails will eager load on boot if cache classes is enabled. Defaults to every folder in the app directory of the application. This kinda sucks though, because it's nice to have caching off in development. |
I'm having this kind of error popping up spontaneously on my production workers. I would say rather rarely. It only sometimes happens upon worker boot-up. Missing classes differ much: uninitialized constant ActiveRecord::Associations::BelongsToAssociation It really seems like the worker has not yet fully loaded all the requirements, but Sidekiq part already has and starting pulling up jobs and throwing them into the threads. Not sure if it's Sidekiq issue or not, but it really seems like it starts working a little too early, like it should just wait for the requirements to load up. Could not reproduce this in dev env, only happens in high-load production. Any thoughts? |
@pokrovskyy What versions of the gems do you have ? did you have the latest version on production ? |
So what's the ideal solution for this problem ? We are also facing this issue in our app with Ruby We have some ruby classes in This is for Sidekiq version: |
You are not the autoloader correctly . If have workers inside a folder, they should be namespaced with the same name of the folder , or required manually.
|
@seuros : Following is the trimmed down code of my current problem
|
@bhaveshf-cuelogic https://github.com/mperham/sidekiq/wiki/Problems-and-Troubleshooting#autoloading You can ask for help and people are welcome to help but I make no attempt to solve autoloading problems. It's always an app problem, not a Sidekiq issue; the best thing to do is review the Rails autoloading guide. https://guides.rubyonrails.org/autoloading_and_reloading_constants.html |
I'm having an issue with sidekiq. Basically we're getting NameError: uninitialized constant on our sidekiq setup which is causing a large number of jobs to fail.
The error log says:
The code is here:
Lock is defined in a library:
And the lib/ folder is automatically loaded with the rest of the configurations.
I have no idea why this is happening. It seems to happen more frequently when we deploy, but it seems to happen often enough otherwise.
I've been following the following thread: #331 but it doesn't seem to offer a solution besides adding the lib folder to the autoload_paths.
I'm using:
Any help would be greatly apreciated.
The text was updated successfully, but these errors were encountered: