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

Race condition in require 'cloudinary' #127

Closed
johnvh opened this issue Oct 8, 2014 · 2 comments
Closed

Race condition in require 'cloudinary' #127

johnvh opened this issue Oct 8, 2014 · 2 comments

Kommentare

@johnvh
Copy link

johnvh commented Oct 8, 2014

There is a race condition when requiring the cloudinary gem. cloudinary/railtie must be required after cloudinary. If it's required during the load of cloudinary, then an exception is throw:

/Users/john/dev/foo/path/ruby/2.1.0/gems/cloudinary-1.0.77/lib/cloudinary/helper.rb:237:in `block in included': undefined method `config' for Cloudinary:Module (NoMethodError)
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/cloudinary-1.0.77/lib/cloudinary/helper.rb:233:in `class_eval'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/cloudinary-1.0.77/lib/cloudinary/helper.rb:233:in `included'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/cloudinary-1.0.77/lib/cloudinary/railtie.rb:6:in `include'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/cloudinary-1.0.77/lib/cloudinary/railtie.rb:6:in `block in <class:Railtie>'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/lazy_load_hooks.rb:36:in `call'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/lazy_load_hooks.rb:27:in `each'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/lazy_load_hooks.rb:27:in `on_load'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/railties-4.1.6/lib/rails/railtie/configuration.rb:69:in `after_initialize'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/cloudinary-1.0.77/lib/cloudinary/railtie.rb:5:in `<class:Railtie>'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/cloudinary-1.0.77/lib/cloudinary/railtie.rb:1:in `<top (required)>'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `block in require'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/cloudinary-1.0.77/lib/cloudinary.rb:12:in `<top (required)>'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `block in require'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
    from /Users/john/dev/foo/lib/foo/bar.rb:1:in `<top (required)>'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `block in require'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
    from /Users/john/dev/foo/test/lib/foo/bar_test.rb:1:in `<top (required)>'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `block in require'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/rake-10.3.2/lib/rake/rake_test_loader.rb:10:in `block (2 levels) in <main>'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/rake-10.3.2/lib/rake/rake_test_loader.rb:9:in `each'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/rake-10.3.2/lib/rake/rake_test_loader.rb:9:in `block in <main>'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/rake-10.3.2/lib/rake/rake_test_loader.rb:4:in `select'
    from /Users/john/dev/foo/path/ruby/2.1.0/gems/rake-10.3.2/lib/rake/rake_test_loader.rb:4:in `<main>'
rake aborted!
Command failed with status (1): [ruby -I"lib:lib:test" -I"/Users/john/dev/foo/path/ruby/2.1.0/gems/rake-10.3.2/lib" "/Users/john/dev/foo/path/ruby/2.1.0/gems/rake-10.3.2/lib/rake/rake_test_loader.rb" "test/**/*_test.rb" ]

See cloudinary.rb line 12:

# lib/cloudinary.rb
require "cloudinary/railtie" if defined?(Rails) && defined?(Rails::Railtie)

If the condition is met there, and cloudinary/railtie is required, then CloudinaryHelper.included ends up running, as it's included in ActionView::Base. If the condition on line #237 of CloudinaryHelper.included gets to the last expression - Cloudinary.config.enhance_image_tag - an exception is raised, as Cloudinary.config has not been defined yet... it's defined later on in cloudinary.rb.

@johnvh
Copy link
Author

johnvh commented Oct 8, 2014

This is on version 1.0.77.

TalLevAmi added a commit that referenced this issue Oct 12, 2014
nadavs added a commit that referenced this issue Nov 4, 2014
…root, which is a String in old Rails versions.Issue #127 - solve cyclical dependency in case cloudinary was included after Rails was initialized
@tocker
Copy link
Contributor

tocker commented Feb 12, 2015

Hi @johnvh,
Can we close this issue?

@tocker tocker closed this as completed Apr 15, 2015
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

2 participants