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

"undefined method on_booted for nil:NilClass" on "pumactl start" #3356

Open
opti opened this issue Mar 29, 2024 · 2 comments
Open

"undefined method on_booted for nil:NilClass" on "pumactl start" #3356

opti opened this issue Mar 29, 2024 · 2 comments

Comments

@opti
Copy link

opti commented Mar 29, 2024

Describe the bug
Having on_booted event in puma configuration file fails to start puma server using pumactl -F config/puma.rb start.

It raises error here since @config.options[:events] is nil

puma/lib/puma/dsl.rb

Lines 706 to 708 in 5fc43d7

def on_booted(&block)
@config.options[:events].on_booted(&block)
end

while trying to load config here:

config = Puma::Configuration.new({ config_files: [@config_file] }, {})
config.load

Puma config:

on_booted do
  puts "on_booted called"
end

To Reproduce

Copy this into a file called hello.ru:

run lambda { |env| [200, {"Content-Type" => "text/plain"}, ["Hello World"]] }

Create config file called puma.rb with the following content:

on_booted do
  puts "on_booted called"
end

Run it with:

bundle exec pumactl -F puma.rb start hello.ru

Observe error:

undefined method `on_booted' for nil:NilClass

The same can be reproduced with test config in the repository:

bundle exec pumactl -F test/config/event_on_booted.rb start test/rackup/hello.ru

Expected behavior
Puma server should start

Desktop:

  • OS: macOS 14.4.1
  • Puma Version 6.4.2
  • ruby 3.2.3
@dentarg
Copy link
Member

dentarg commented Mar 29, 2024

One-liner to reproduce:

$ echo 'app { [200, {}, ["OK"]] }; on_booted { puts "puma booted" }' | ruby -Ilib bin/pumactl --config-file /dev/stdin start
undefined method `on_booted' for nil:NilClass

I guess #2709 never tested with pumactl

Just to be clear, the hook works using puma

$ echo 'app { [200, {}, ["OK"]] }; on_booted { puts "puma booted" }' | ruby -Ilib bin/puma --config /dev/stdin --port 0 --log-requests
Puma starting in single mode...
* Puma version: 6.4.2 (ruby 3.2.3-p157) ("The Eagle of Durango")
*  Min threads: 0
*  Max threads: 5
*  Environment: development
*          PID: 26832
* Listening on http://0.0.0.0:61890
Use Ctrl-C to stop
puma booted
^C- Gracefully stopping, waiting for requests to finish
=== puma shutdown: 2024-03-29 09:46:32 +0100 ===
- Goodbye!

@dentarg
Copy link
Member

dentarg commented Mar 29, 2024

Looks like events is missing at

config = Puma::Configuration.new({ config_files: [@config_file] }, {})

as a61b078 added that in several places

However, wouldn't it be better to make events part of the default configuration? Is there anything preventing us from that?

class Configuration
DEFAULTS = {
auto_trim_time: 30,
binds: ['tcp://0.0.0.0:9292'.freeze],
clean_thread_locals: false,
debug: false,
early_hints: nil,
environment: 'development'.freeze,
# Number of seconds to wait until we get the first data for the request.
first_data_timeout: 30,
# Number of seconds to wait until the next request before shutting down.
idle_timeout: nil,
io_selector_backend: :auto,
log_requests: false,
logger: STDOUT,
# How many requests to attempt inline before sending a client back to
# the reactor to be subject to normal ordering. The idea here is that
# we amortize the cost of going back to the reactor for a well behaved
# but very "greedy" client across 10 requests. This prevents a not
# well behaved client from monopolizing the thread forever.
max_fast_inline: 10,
max_threads: Puma.mri? ? 5 : 16,
min_threads: 0,
mode: :http,
mutate_stdout_and_stderr_to_sync_on_write: true,
out_of_band: [],
# Number of seconds for another request within a persistent session.
persistent_timeout: 20,
queue_requests: true,
rackup: 'config.ru'.freeze,
raise_exception_on_sigterm: true,
reaping_time: 1,
remote_address: :socket,
silence_single_worker_warning: false,
silence_fork_callback_warning: false,
tag: File.basename(Dir.getwd),
tcp_host: '0.0.0.0'.freeze,
tcp_port: 9292,
wait_for_less_busy_worker: 0.005,
worker_boot_timeout: 60,
worker_check_interval: 5,
worker_culling_strategy: :youngest,
worker_shutdown_timeout: 30,
worker_timeout: 60,
workers: 0,
http_content_length_limit: nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants