rubybundlersidekiq

Ruby: Unable to start worker - check_for_activated_spec


I am unable to run some of my jobs in sidekiq. And it seems to be somehow related to Bundler.. Maybe.

when I run my puma server with pumactl start in the logs I am getting:

[156149] ! Unable to start worker
[156149] /home/todd/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/bundler-2.3.25/lib/bundler/runtime.rb:309:in `check_for_activated_spec!'

Currently I'm on sidekiq 6.5.6 and Bundler 2.3.25

Anyone know of any issues with those two versions or anything else that may be causing this?

EDIT: The interesting thing is when I start puma with bundle exec pumactl start I get a totally different error:

[ActionDispatch::HostAuthorization::DefaultResponseApp] Blocked host:

But my host is defined in my development.rb file.. in fact I've added the following, so NO hosts should be blocked:

  config.hosts << /.*\.ngrok\.io/
  config.hosts.clear

Then finally if I just start puma with a rails s all is fine, just my sidekiq worker won't run correctly.


Solution

  • Let's say that you want to start using Rails and one day you follow the general installation instructions which say that you should run this command:

    gem install rails
    

    And you get this output:

    ...
    Successfully installed rails-7.0.1
    

    You also start working with puma and sidekiq and install those gems for the convenience of running pumactl start and sidekiq:

    gem install puma
    ...
    Successfully installed puma-5.6.2
    
    gem install sidekiq
    ...
    Successfully installed sidekiq-6.4.2
    

    Then after a day or a week or a month of tinkering you create a new Rails app:

    rails new app
    

    And since you want to use Sidekiq you add that to your Gemfile, which looks something like this:

    # frozen_string_literal: true
    
    source 'https://rubygems.org'
    git_source(:github) { |repo| "https://github.com/#{repo}.git" }
    
    gem "puma", "~> 5.6.2"
    gem "rails", "~> 7.0.1"
    gem "sidekiq", "~> 6.0"
    

    But you know that there are newer versions of those gems so you update your Gemfile to look like this:

    # frozen_string_literal: true
    
    source 'https://rubygems.org'
    git_source(:github) { |repo| "https://github.com/#{repo}.git" }
    
    gem "puma", "~> 6.0.0"
    gem "rails", "~> 7.0.4"
    gem "sidekiq", "~> 7.0"
    

    And then you run bundle install and the gems update. Or maybe you don't change the versions, but some day run bundle update which uses the ~> versioning operator and updates the gems to newer versions.

    Here's where you're going to start running into compatibility problems.

    First problem:

    1. When you installed the sidekiq and puma and rails gems to run their scripts like pumactl they were installed using gem install ... which installed them globally and with a specific version.
    2. When you added them to your Rails app and updated the versions they were installed separately by bundler with specific versions that are noted in Gemfile.lock.
    3. Now your global version of puma is 5.6.2 and your bundled version of puma is 6.0.0.

    Trying to manage puma using an old version of the CLI with a new version of the gem isn't guaranteed to work and can introduce hard-to-pinpoint problems. The same is true of the rails and sidekiq gems and any gem with a CLI.

    Second problem:

    1. When you run scripts like pumactl they aren't necessarily going to look at your application's Gemfile.lock and they aren't guaranteed to see or respect bundler's configuration for your Rails app when it loads it.
    2. When you run scripts prefixed with bundle exec (like bundle exec sidekiq) it uses bundler to look at your bundled environment and ensure that all the dependencies are properly loaded.

    Trying to run a bundled application without bundle exec can introduce hard-to-pinpoint problems. The same is true for any gems that have CLI tools.

    Short answer

    Always use bundle exec ... to run gem CLIs in your app, whether it's bundle exec rails server or bundle exec puma or bundle exec sidekiq. This will ensure that your app is started or managed using the bundled gem rather than the global version.

    If you see errors when starting your app using bundle exec ... then pay attention to them because they are indicative of actual problems that need to be addressed. Likewise, if you do see errors with bundle exec but don't see errors when starting your app using globally installed gems then pay attention to them because it means your app is not portable -- it's likely that it is papering over bugs to make the app run and that your app will not run on another computer.

    Extended answer

    Because the errors that you're reporting are due to a misconfiguration of your system and app, I can't give you any more detailed answers. You need to fix your configuration first and determine which of the three different errors you're experiencing is valid.