Skip to content

Drop the before_fork/on_worker_boot advice - #31241

Merged
matthewd merged 1 commit into
rails:masterfrom
matthewd:no-after-fork
Dec 1, 2017
Merged

matthewd merged 1 commit into
rails:masterfrom
matthewd:no-after-fork

Conversation

@matthewd

Copy link
Copy Markdown
Member

It's no longer required for Active Record, and other common libraries (dalli, redis-rb) all seem to be fork-proof too.

I was going to drop the more obscure before_fork but keep on_worker_boot... but I couldn't come up with a way to describe when it's necessary or what to do, nor a plausible example. (Not because it's hard to describe the problem it fixes, but because the "except for all common libraries" exception makes it sound silly and confusing.)

Maybe we can just drop it entirely. If most people don't need it, it seems fine to treat it like any other Puma config option that exists but isn't promoted in the generated file.

Alternatively, does anyone have any other good examples of widely-seen code that apps need in one or both of these? CodeTriage says no; Discourse does a lot, but nothing that strikes me as needing general promotion.

cc @schneems @nateberkopec

(this is follow-on from #31221 and #31173, which remove the need for AR connection management)

It's no longer required for Active Record, and other common libraries
(dalli, redis-rb) all seem to be fork-proof too.
@matthewd
matthewd merged commit e40a00e into rails:master Dec 1, 2017
@matthewd
matthewd deleted the no-after-fork branch December 2, 2017 02:23
@fredngo

fredngo commented Apr 11, 2018 •

Copy link
Copy Markdown

@matthewd

Does this mean that if we have existing before_fork and on_worker_boot blocks in our pre-Rails 5.2.0 puma.rb file, we can now simply remove those blocks after upgrading to Rails 5.2.0?

The Puma repo still recommends the use of these blocks in its documentation:

If you're preloading your application and using ActiveRecord, it's recommended that you setup your connection pool [in on_worker_boot]

So there's just a little bit of conflicting information here. But I recognize that Rails 5.2.0 just came out so hopefully documentation will converge and this query will add a bit to that effort.

@matthewd

Copy link
Copy Markdown
Member Author

Does this mean that if we have existing before_fork and on_worker_boot blocks in our pre-Rails 5.2.0 puma.rb file, we can now simply remove those blocks after upgrading to Rails 5.2.0?

Yes. (Assuming they're doing AR connection management, of course.)

They're perfectly safe to leave there, so it's not called out in the upgrade guide, but they should no longer be necessary.

ledermann added a commit to ledermann/docker-rails that referenced this pull request Apr 26, 2018
runephilosof-abtion added a commit to abtion/rails-template that referenced this pull request Feb 23, 2021
Since Rails 5.2, it is no longer needed.
rails/rails#31241

Now the file matches the `rails app:update` more closely.
@matthewd matthewd mentioned this pull request Sep 16, 2024
4 tasks done
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

Successfully merging this pull request may close these issues.

3 participants