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

Eager load the constants #102

Merged
merged 1 commit into from
Aug 16, 2017
Merged

Conversation

y-yagi
Copy link
Member

@y-yagi y-yagi commented Aug 12, 2017

In a thread-based backend like Sidekiq, there is a possibility that autoload may occur simultaneously in multiple threads, and as a result, it is presumed that an error may be caused by contention of autoload.

In order to avoid the above issue, eager load the constants on boot.
Maybe fixes #101

Context: rails/rails#30217 (comment)

@rails-bot
Copy link

r? @kaspth

(@rails-bot has picked a reviewer for you, use r? to override)

Copy link
Contributor

@kaspth kaspth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API docs say we don't need to add the file paths. Will it work without them here?

http://api.rubyonrails.org/classes/ActiveSupport/Autoload.html#method-i-eager_autoload

@@ -1,9 +1,14 @@
require 'global_id/global_id'
require 'active_support'

autoload :SignedGlobalID, 'global_id/signed_global_id'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also need to eager load this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree.
But SignedGlobalID is defined at Top level. Is eager load usable in that case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really. We can implement self.eager_load! in GlobalID and make it require that file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, thank you! I fixed.

@rafaelfranca
Copy link
Member

We also need to add GlobalID to the eager_load_namespaces in the railtie.

@matthewd
Copy link
Member

This is a rather complicated work-around for a Ruby bug that no-one's managed to reproduce. 😢

If people who've experienced the problem (and therefore obviously have a setup that's theoretically capable of reproducing) could help track down the upstream bug, we could stop chasing autoloads through every gem.

@rafaelfranca
Copy link
Member

It seems like a workaround for that bug it is rather a way to improve CoW mechanism of the gem. Instead of loading that constant in every forked process we do load it only in the parent process. Regardless of that bug I think this should be implemented.

@y-yagi
Copy link
Member Author

y-yagi commented Aug 15, 2017

Will it work without them here?

Looks it works without them. I removed files paths.

In a thread-based backend like Sidekiq, there is a possibility that
autoload may occur simultaneously in multiple threads, and as a result,
it is presumed that an error may be caused by contention of autoload.

In order to avoid the above issue, eager load the constants on boot.
Maybe fixes rails#101
@rafaelfranca rafaelfranca merged commit c41b321 into rails:master Aug 16, 2017
@y-yagi y-yagi deleted the eager_load_constants branch August 16, 2017 20:28
@joaquinmoreira
Copy link

Are you planning to release an update to the gem with these changes?

@rafaelfranca
Copy link
Member

Yes. 0.4.1 was just released

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

Successfully merging this pull request may close these issues.

Error while trying to deserialize arguments: uninitialized constant GlobalID::Locator
6 participants