Skip to content

Puma fails to boot in production with default config due to missing Concurrency constant (Rails 7.1.0.beta1) #49323

@mattbrictson

Description

@mattbrictson

Steps to reproduce

  1. Generate an app using rails new with Rails 7.1.0.beta1
  2. Run RAILS_ENV=production bundle exec puma -C ./config/puma.rb

Expected behavior

Puma should start.

Actual behavior

./config/puma.rb:16:in `block in _load_from': uninitialized constant Puma::DSL::Concurrent (NameError)
	from ./config/puma.rb:16:in `fetch'
	from ./config/puma.rb:16:in `_load_from'

The problem lies in the config/puma.rb file generated by rails new, specifically this statement that was added in #46838:

ENV.fetch("WEB_CONCURRENCY") { Concurrent.physical_processor_count }

At the time Puma evals this statement, Bundler.require has not yet been run, and so the concurrent-ruby gem has not yet been loaded. That is why the Concurrent constant is not defined and we see an uninitialized constant error when Puma starts.

Workaround

Set the WEB_CONCURRENCY env var or change the ENV.fetch statement config/puma.rb as follows:

ENV.fetch("WEB_CONCURRENCY") do
  require "concurrent-ruby"
  Concurrent.physical_processor_count
end

System configuration

Rails version: 7.1.0.beta1

Ruby version: 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-darwin22]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions