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

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

Closed
maxkwallace opened this issue Dec 3, 2015 · 7 comments
Closed

Comments

@maxkwallace
Copy link
Contributor

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?

@tpodom
Copy link

tpodom commented Mar 14, 2016

Looking at the source I think this is an error in documentation and naming. The underlying code registers an after_worker_fork callback which parallels before_worker_fork and it appears both of those callback happen in the master process. It does not look like there is any support for the documented after_worker_boot. I'm currently looking to see if there's any workaround because I'm trying to register Bunny consumers after Rails has loaded.

@maxkwallace
Copy link
Contributor Author

@tpodom Thanks for the reply!

@evanphx evanphx closed this as completed Apr 7, 2016
@tpodom
Copy link

tpodom commented Apr 7, 2016

@evanphx I saw this was closed but I'm not sure why. It seems like either after_worker_boot should be renamed to after_worker_fork, or it's documentation should be updated to make it clear that it's after a worker is forked in the master process, or it should be updated to work as described.

@evanphx
Copy link
Member

evanphx commented Apr 7, 2016

Well, I can't rename those now because that would break peoples config files. The docs just need to be be clear that it happens in the master, i'll do that.

evanphx added a commit that referenced this issue Apr 7, 2016
@evanphx
Copy link
Member

evanphx commented Apr 7, 2016

I fixed the name, because it was confusing, leaving an alias for the old name.

@tpodom
Copy link

tpodom commented Apr 7, 2016

@evanphx thanks, that will be much more clear going forward

maxkwallace added a commit to maxkwallace/puma that referenced this issue Apr 11, 2016
@maxkwallace
Copy link
Contributor Author

@evanphx Thanks! The updated documentation is super helpful. I noticed two tiny inconsistencies so I sent over a PR: #956

evanphx added a commit that referenced this issue Apr 12, 2016
Tiny fixes in hook documentation for #840
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants