Skip to content

Config hook execution order doesn't seem to match examples/config.rb #840

@marisawallace

Description

@marisawallace

I'm trying to gain a better understanding of how Puma works. I'm running Puma in cluster mode, with preload_app!, and my config/puma.rb looks like:

...

on_worker_boot do
  puts "on_worker_boot for pid #{Process.pid}"
end

before_fork do
  puts "before_fork for pid #{Process.pid}"
end

after_worker_boot do
  puts "after_worker_boot for pid #{Process.pid}"
end

When I start Puma, I see:

before_fork for pid 17069
after_worker_boot for pid 17069
after_worker_boot for pid 17069
on_worker_boot for pid 17082
on_worker_boot for pid 17085
[17069] - Worker 0 (pid: 17082) booted, phase: 0
[17069] - Worker 1 (pid: 17085) booted, phase: 0

This doesn't match my expectations based on reading examples/config.rb. To paraphrase from the file, on_worker_boot is for

... when a worker boots to setup the process before booting the app.

and after_worker_boot is for

...when a worker boots to setup the process after booting the app.

Based on that documentation, I would expect the after_worker_boot hook to run in each worker process, after the on_worker_boot hook. But this doesn't match what I see in my console-- the after_worker_boot hook is being run first, and only in the parent process.

What's the source of this misunderstanding?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions