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

Disconnects all connections in the pool before forking. #26314

merged 1 commit into from Sep 13, 2016


None yet
8 participants

frodsan commented Aug 29, 2016

Taken from this discussion: puma/puma#1001

If you're preloading your application and using ActiveRecord, it's recommended that you close any connections to the database here to prevent connection leakage:

# config/puma.rb
before_fork do

/cc @schneems


This comment has been minimized.

rails-bot commented Aug 29, 2016

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @kaspth (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

@maclover7 maclover7 added the railties label Aug 29, 2016


This comment has been minimized.


maclover7 commented Aug 29, 2016


This comment has been minimized.


evanphx commented Aug 29, 2016

Seems like good advice. Only matters if initializers make queries.


This comment has been minimized.


pixeltrix commented Aug 29, 2016

If we have the before_fork block uncommented then uncommenting the on_worker_boot code becomes redundant doesn't it since Active Record will detect there isn't an active connection and establish one itself. I guess there's a possible scenario where you might want to not preload your app - too much memory mainly 😄


This comment has been minimized.


schneems commented Sep 6, 2016

I think this is fine. The issue here isn't that the app won't be able to connect to the database but more that the master server will potentially have open connections that aren't being used. For postgres the number of open connections can be a big problem on larger apps. Explicitly disconnecting before forking would prevent any accidentally opened connections from hanging around longer than is needed.


This comment has been minimized.


kaspth commented Sep 8, 2016

@rails-bot rails-bot assigned pixeltrix and unassigned kaspth Sep 8, 2016

@schneems schneems merged commit d4bbac8 into rails:master Sep 13, 2016

2 checks passed

codeclimate Code Climate didn't find any new or fixed issues.
continuous-integration/travis-ci/pr The Travis CI build passed

@frodsan frodsan deleted the frodsan:puma-ar-disconnect branch Sep 13, 2016


This comment has been minimized.


fxn commented Sep 19, 2016

Please remember "Active Record" has a space. Fixed in 1b6f3a2.

christiannelson added a commit to carbonfive/raygun-rails that referenced this pull request Sep 20, 2016

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