-
Notifications
You must be signed in to change notification settings - Fork 1.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
Autoload race condition: uninitialized constant errors #2255
Comments
Interesting. I haven't run on Rails 5 yet. In the past I have used an initializer with ActiveSupport.on_load(:action_controller) do
require 'active_model_serializers/register_jsonapi_renderer'
ActiveModelSerializers.eager_load! if Rails.env.production?
ActiveModelSerializers::Adapter::JsonApi.eager_load! if Rails.env.production?
require 'active_model/serializer/null'
ActiveModel::Serializer::Null
end |
How come you're not using a release? |
From the ActiveSupport::Autoload source I draw the conclusion that calling Went also with an initializer but loading the constants explicitly on boot: ActiveModelSerializers::Deserialization
ActiveModelSerializers::Adapter::JsonApi::Relationship
ActiveModelSerializers::Adapter::JsonApi::ResourceIdentifier Haven't seen the errors again since deployed. Platformatec's blog post Eager loading for greater good is a good read on this topic.
Oh, we are using |
Looks like we can add this to the docs as an FAQ of some sort, if you'd like to make a PR |
facing a similar issue: uninitialized constant ActiveModelSerializers::Adapter::JsonApi::Meta So what is the work around here? From what I understand, we can write all the constants in an initializer. Is a list or some way with which we can do this for all in a well-practiced manner? Rails is 5.1.6 |
@GeminPatel I'm not sure how Rails 5 would differ, but have you tried an initializer like what I described #2255 (comment) |
Rails 5 unhooks autoloading (#a71350c) after the application has booted. I suspect the error originates from this gem not explicitly loading all deps during application boot. The initializer is a workaround which actually forces autoloading during application boot. @bf4 #3f65eba fixes the issue. Would you be interesetd in a pull request? |
Yup, also generally help not leaving ams completely abandoned :)
…On Mon, Oct 8, 2018, 2:46 AM Fabian Mersch ***@***.***> wrote:
Rails 5 unhooks autoloading (#a71350c
<rails/rails@a71350c#diff-bf85cfa3d5f11bd1db1c97843818351b>)
after the application has booted. I suspect the error originates from this
gem not explicitly loading all deps during application boot.
The initializer is a workaround which actually forces autoloading during
application boot.
@bf4 <https://github.com/bf4> #3f65eba
<f-mer/active_model_serializers@3f65eba>
fixes the issue. Would you be interesetd in a pull request?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2255 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAIuQsgs07DTOqEeqUDrc_9BuDM1pAZUks5uiwLagaJpZM4UJ8aH>
.
|
This is more like a hypothesis than a straight bug report.
Expected behavior vs actual behavior
Using ActiveModelSerializers with a threaded web server (in my case puma) I get infrequent
uninitialized constant
errors. I think it's caused by the use ofautoload
. I guess that ActiveSupportsautoload
is not threadsafe and on application boot not all modules / classes are necessarily implicitly loaded.Steps to reproduce
I'm not sure there is a way to reproduce. I think it's a race condition which only emerges under load.
Environment
ActiveModelSerializers Version (commit ref if not on tag):
0-10-stable
Output of
ruby -e "puts RUBY_DESCRIPTION"
:ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]
Rails Version:
5.1.4
Errors
Additonal helpful information
I'm trying to solve the problem in this fork. Adding
ActiveModelSerializers::Adapter::JsonApi
toeager_load_namespaces
inapplication.rb
.This problem might also be cause by the deactivation of dependency loading in rails 5?
The text was updated successfully, but these errors were encountered: