Skip to content

Commit 2114b85

Browse files
authored
Default PUMA_PERSISTENT_TIMEOUT to match router 2.0 (#454)
Router 2.0 introduced keepalive support. It will close idle connections after 90 seconds (https://devcenter.heroku.com/articles/http-routing#keepalives). We want to avoid a situation where they send a request right before Puma closes the connection. We can do that by setting it to the same timeout the router uses + some value (such as 5 seconds). Puma 7.0 was just released, and I suggested we make that value configurable via env var puma/puma#3378. This sets the value for any Puma user to do this manually, in their `config/puma.rb`, and for Puma 7+ users they will get that value by default.
1 parent a480a09 commit 2114b85

File tree

4 files changed

+7
-0
lines changed

4 files changed

+7
-0
lines changed

buildpacks/ruby/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Set default `export PUMA_PERSISTENT_TIMEOUT=95` to match recommended router 2.0 settings[#454](https://github.com/heroku/buildpacks-ruby/pull/454)
13+
1014
## [12.0.0] - 2025-09-08
1115

1216
### Changed

buildpacks/ruby/src/steps/default_env.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub(crate) fn default_env(
5555
("RAILS_LOG_TO_STDOUT", "enabled"),
5656
("MALLOC_ARENA_MAX", "2"),
5757
("DISABLE_SPRING", "1"),
58+
("PUMA_PERSISTENT_TIMEOUT", "95"),
5859
]
5960
.iter()
6061
.fold(LayerEnv::new(), |layer_env, (name, value)| {

buildpacks/ruby/tests/integration_test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ fn test_default_app_ubuntu24() {
155155
LD_LIBRARY_PATH=/layers/heroku_ruby/binruby/lib
156156
MALLOC_ARENA_MAX=2
157157
PATH=/workspace/bin:/layers/heroku_ruby/bundler/bin:/layers/heroku_ruby/gems/bin:/layers/heroku_ruby/bundler/bin:/layers/heroku_ruby/binruby/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
158+
PUMA_PERSISTENT_TIMEOUT=95
158159
RACK_ENV=production
159160
RAILS_ENV=production
160161
RAILS_LOG_TO_STDOUT=enabled

docs/application_contract.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,4 @@ Once an application has passed the detect phase, the build phase will execute to
7676
- Executables from gems will take precedence over executables that ship with Ruby (for example `rake` installed from `bundle install` should be loaded before `rake` that comes with the compiled Ruby binary).
7777
- `RAILS_LOG_TO_STDOUT="enabled"` - Sets the default logging target to STDOUT for Rails 5+ apps. [details](https://blog.heroku.com/container_ready_rails_5)
7878
- `RAILS_SERVE_STATIC_FILES="enabled"` - Enables the `ActionDispatch::Static` middleware for Rails 5+ apps so that static files such as those in `public/assets` are served by the Ruby webserver such as Puma [details](https://blog.heroku.com/container_ready_rails_5).
79+
- `PUMA_PERSISTENT_TIMEOUT=95` - Sets an [idle timeout value that aligns with Heroku's Router 2.0](https://devcenter.heroku.com/articles/http-routing#keepalives). This value is [automatically adopted by Puma 7+ applications](https://github.com/search?q=repo%3Apuma%2Fpuma+PUMA_PERSISTENT_TIMEOUT&type=pullrequests). Applications using Puma 6 or prior can use it manually in their `config/puma.rb`. Applications using a different web server can use it as a stable source of suggested idle timeout information.

0 commit comments

Comments
 (0)