rails / solid_queue

Database-backed Active Job backend
MIT License
1.66k stars 90 forks source link

Puma plugin fails with `NameError` #241

Open MrSerth opened 1 month ago

MrSerth commented 1 month ago

We've just integrated solid_queue in our Rails app and want to use the puma plugin to run Solid Queue's supervisor. However, with our current puma config, this fails:

/.rvm/gems/ruby-3.3.2/gems/solid_queue-0.3.3/lib/puma/plugin/solid_queue.rb:13:in `block (2 levels) in start': uninitialized constant SolidQueue (NameError)

        SolidQueue::Supervisor.start(mode: :all)
        ^^^^^^^^^^
    from /.rvm/gems/ruby-3.3.2/gems/solid_queue-0.3.3/lib/puma/plugin/solid_queue.rb:11:in `fork'
    from /.rvm/gems/ruby-3.3.2/gems/solid_queue-0.3.3/lib/puma/plugin/solid_queue.rb:11:in `block in start'
    from /.rvm/gems/ruby-3.3.2/gems/puma-6.4.2/lib/puma/events.rb:17:in `block in fire'
    from /.rvm/gems/ruby-3.3.2/gems/puma-6.4.2/lib/puma/events.rb:17:in `each'
    from /.rvm/gems/ruby-3.3.2/gems/puma-6.4.2/lib/puma/events.rb:17:in `fire'
    from /.rvm/gems/ruby-3.3.2/gems/puma-6.4.2/lib/puma/events.rb:46:in `fire_on_booted!'
    from /.rvm/gems/ruby-3.3.2/gems/puma-6.4.2/lib/puma/cluster.rb:495:in `run'
    from /.rvm/gems/ruby-3.3.2/gems/puma-6.4.2/lib/puma/launcher.rb:194:in `run'
    from /.rvm/gems/ruby-3.3.2/gems/puma-6.4.2/lib/puma/cli.rb:75:in `run'
    from /.rvm/gems/ruby-3.3.2/gems/puma-6.4.2/bin/puma:10:in `<top (required)>'
    from /.rvm/gems/ruby-3.3.2/bin/puma:25:in `load'
    from /.rvm/gems/ruby-3.3.2/bin/puma:25:in `<main>'
    from /.rvm/gems/ruby-3.3.2/bin/ruby_executable_hooks:22:in `eval'
    from /.rvm/gems/ruby-3.3.2/bin/ruby_executable_hooks:22:in `<main>'
[95129] ! reaped unknown child process pid=95143 status=pid 95143 exit 1

I've reduced our puma.rb config and also reproduced the issue with a new Rails app.

Steps to reproduce:

  1. Create a new Rails app: rails new "solid_queue" -T --api --no-tests
  2. Add the gem to the Gemfile gem "solid_queue"
  3. Run bundle install
  4. Install with rails generate solid_queue:install
  5. Migrate with rails db:migrate
  6. Modify the puma.rb config: a. Configure workers to be used, i.e. workers 2 b. Add preload_app! false
  7. Start the app through Puma with bundle exec puma
  8. ⚡️ See the above name error.

Even without starting the app through puma, I was able to reproduce the error with the following steps:

Steps to reproduce:

  1. Create a new Rails app: rails new "solid_queue" -T --api --no-tests
  2. Add the gem to the Gemfile gem "solid_queue"
  3. Run bundle install
  4. Install with rails generate solid_queue:install
  5. Migrate with rails db:migrate
  6. Modify the puma.rb config: a. Configure workers to be used, i.e. workers 2 b. Add prune_bundler
  7. Start the app regularly through rails s
  8. ⚡️ See the above name error.

In our production environment, we use a combination of the puma command with preload_app! false ("replaced" by fork_worker) and prune_bundler for phased restarts. Obviously, this configuration isn't supported by the puma plugin.

Ruby: 3.3.2 +YJIT Rails: 7.1.3.4 Puma: 6.4.2 Solid Queue: 0.3.3