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

Fix #6 by adding active_support require which ShardThreadRegistry depends on #10

Merged

Conversation

mwallba
Copy link
Contributor

@mwallba mwallba commented Feb 21, 2020

Hi @hsgubert !
Thanks for this awesome gem - helped me out big time in upgrading a legacy up while not wanting to give up on sharding

This PR fixes #6

The issue does not occur because of JRuby but because the necessary active_support dependency has not been loaded yet via one of the railties/engines in config/application.rb and bundler has not yet required the dependencies from the Gemfile, which also could've setup active_support.

I suspect OP in #6 probably had Sprockets and other pieces deactivated in their fresh new app.

By explicitly adding the dependency in ShardThreadRegistry this gets fixed.

You can reconstruct the scenario by not adding Sprockets to a fresh rails 5.1.7 install:
rails _5.1.7_ new -S broken_app
cd broken_app
bundle add rails-sharding

~/broken_app(master ✗) bundle exec rails g rails_sharding:scaffold
/Users/mwallba/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rails-sharding-1.1.3/lib/rails/sharding/shard_thread_registry.rb:7:in `<class:ShardThreadRegistry>': undefined method `thread_mattr_accessor' for Rails::Sharding::ShardThreadRegistry:Class (NoMethodError)
	from /Users/mwallba/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rails-sharding-1.1.3/lib/rails/sharding/shard_thread_registry.rb:2:in `<module:Sharding>'
	from /Users/mwallba/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rails-sharding-1.1.3/lib/rails/sharding/shard_thread_registry.rb:1:in `<top (required)>'
	from /Users/mwallba/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rails-sharding-1.1.3/lib/rails/sharding/core.rb:5:in `require'
	from /Users/mwallba/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rails-sharding-1.1.3/lib/rails/sharding/core.rb:5:in `<top (required)>'
	from /Users/mwallba/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rails-sharding-1.1.3/lib/rails/sharding.rb:4:in `require'
	from /Users/mwallba/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rails-sharding-1.1.3/lib/rails/sharding.rb:4:in `<top (required)>'
	from /Users/mwallba/.rbenv/versions/2.6.5/lib/ruby/2.6.0/bundler/runtime.rb:95:in `require'
	from /Users/mwallba/.rbenv/versions/2.6.5/lib/ruby/2.6.0/bundler/runtime.rb:95:in `rescue in block in require'
	from /Users/mwallba/.rbenv/versions/2.6.5/lib/ruby/2.6.0/bundler/runtime.rb:72:in `block in require'
	from /Users/mwallba/.rbenv/versions/2.6.5/lib/ruby/2.6.0/bundler/runtime.rb:65:in `each'
	from /Users/mwallba/.rbenv/versions/2.6.5/lib/ruby/2.6.0/bundler/runtime.rb:65:in `require'
	from /Users/mwallba/.rbenv/versions/2.6.5/lib/ruby/2.6.0/bundler.rb:114:in `require'
	from /Users/mwallba/broken_app/config/application.rb:17:in `<top (required)>'
	from /Users/mwallba/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:92:in `require'
	from /Users/mwallba/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:92:in `preload'
	from /Users/mwallba/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:157:in `serve'
	from /Users/mwallba/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:145:in `block in run'
	from /Users/mwallba/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:139:in `loop'
	from /Users/mwallba/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:139:in `run'
	from /Users/mwallba/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application/boot.rb:19:in `<top (required)>'
	from /Users/mwallba/.rbenv/versions/2.6.5/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
	from /Users/mwallba/.rbenv/versions/2.6.5/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
	from -e:1:in `<main>'

After adding the dependency fix, everything works fine.

I ran into this issue while checking a client's Gemfile with bumbler

Copy link
Owner

@hsgubert hsgubert left a comment

Choose a reason for hiding this comment

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

@mwallba this is probably long due. Just checking if you still need this change and if you confirm it fixes Issue #6

@mwallba
Copy link
Contributor Author

mwallba commented Jul 8, 2021

@hsgubert yup this still fixes #6 - we're still using the gem just in case you consider rolling out a new release.

@mwallba
Copy link
Contributor Author

mwallba commented Jul 9, 2021

@hsgubert do you want me to change/add anything to get this merged or is this good to go from your side?

@hsgubert
Copy link
Owner

No @mwallba, this looks good already. Thanks!

@hsgubert hsgubert merged commit 15b2c20 into hsgubert:master Jul 10, 2021
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.

undefined method `thread_mattr_accessor' for Rails::Sharding::ShardThreadRegistry:Class
2 participants