puma 6.6.1 → 7.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/History.md +130 -4
- data/README.md +11 -24
- data/docs/fork_worker.md +5 -5
- data/docs/kubernetes.md +6 -4
- data/docs/restart.md +2 -2
- data/docs/signals.md +9 -9
- data/docs/stats.md +2 -1
- data/ext/puma_http11/extconf.rb +2 -17
- data/ext/puma_http11/mini_ssl.c +18 -8
- data/ext/puma_http11/org/jruby/puma/Http11.java +9 -1
- data/ext/puma_http11/puma_http11.c +23 -11
- data/lib/puma/binder.rb +10 -8
- data/lib/puma/cli.rb +3 -5
- data/lib/puma/client.rb +31 -31
- data/lib/puma/cluster/worker.rb +9 -10
- data/lib/puma/cluster/worker_handle.rb +36 -5
- data/lib/puma/cluster.rb +12 -13
- data/lib/puma/cluster_accept_loop_delay.rb +92 -0
- data/lib/puma/commonlogger.rb +3 -3
- data/lib/puma/configuration.rb +88 -43
- data/lib/puma/const.rb +9 -10
- data/lib/puma/control_cli.rb +6 -2
- data/lib/puma/detect.rb +2 -0
- data/lib/puma/dsl.rb +108 -81
- data/lib/puma/error_logger.rb +3 -1
- data/lib/puma/events.rb +25 -10
- data/lib/puma/io_buffer.rb +8 -4
- data/lib/puma/launcher/bundle_pruner.rb +1 -1
- data/lib/puma/launcher.rb +28 -29
- data/lib/puma/minissl.rb +0 -1
- data/lib/puma/plugin/systemd.rb +3 -3
- data/lib/puma/rack/urlmap.rb +1 -1
- data/lib/puma/reactor.rb +19 -4
- data/lib/puma/request.rb +33 -24
- data/lib/puma/runner.rb +8 -17
- data/lib/puma/server.rb +114 -68
- data/lib/puma/single.rb +4 -1
- data/lib/puma/thread_pool.rb +37 -81
- data/lib/puma/util.rb +0 -7
- data/lib/puma.rb +10 -0
- data/lib/rack/handler/puma.rb +2 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13d2ebef5879f5ab45b75cadd20e4a72b643ff9f5e6af2cbcf69d655ec4475b8
|
4
|
+
data.tar.gz: 1ce847fac6f3e5f893814462b47792db32f1cb0960b9c8619d7ad26c4057bfec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e67841b0a72c35c6667745e0aad11b152dbd46dc952b51ec811100281f8d93e45bc70fd16861b848918790b2eb0b0b290fa493f82beb0e4ed818abdffcb2f9fc
|
7
|
+
data.tar.gz: cecf1704d003e0f0299811a6c16310bb79fd7ee5ff21ce991bb2b82430f2d31e348a65b4054e57656255af10ac62489e4c4df889367a6c0b967d540522717ea7
|
data/History.md
CHANGED
@@ -1,3 +1,88 @@
|
|
1
|
+
## 7.0.4 / 2025-09-23
|
2
|
+
|
3
|
+
* Bugfixes
|
4
|
+
* Fix SSL_shutdown error handling ([#3703])
|
5
|
+
* Strip whitespace from the beginnings of request header values. ([#3742])
|
6
|
+
|
7
|
+
* Performance
|
8
|
+
* puma_http11.c: Use interned UTF-8 strings for hash keys ([#3754])
|
9
|
+
* Move sleep cluster logic to its own class ([#3746], [#3740])
|
10
|
+
|
11
|
+
## 7.0.3 / 2025-09-13
|
12
|
+
|
13
|
+
* Performance
|
14
|
+
* server.rb - process_client - add ka to todo if readable & complete ([#3748])
|
15
|
+
|
16
|
+
* Bugfixes
|
17
|
+
* Convert PUMA_PERSISTENT_TIMEOUT to an Integer ([#3749])
|
18
|
+
|
19
|
+
## 7.0.2 / 2025-09-08
|
20
|
+
|
21
|
+
* Bugfixes
|
22
|
+
* bug: control_cli.rb - Fixup `pumactl` code to load puma.rb for `deprecate_method_change` ([#3736], [#3734])
|
23
|
+
* Replace sleep spin lock with condition variable ([#3729])
|
24
|
+
* Fix Puma not booting if queue_requests disabled ([#3731])
|
25
|
+
|
26
|
+
## 7.0.1 / 2025-09-06
|
27
|
+
|
28
|
+
* Bugfixes
|
29
|
+
* Add backward compatibility aliases for Events class methods ([#3725])
|
30
|
+
|
31
|
+
## 7.0.0 / 2025-09-03
|
32
|
+
|
33
|
+
* Breaking changes
|
34
|
+
* Set default `max_keep_alive` to 999 ([#3719])
|
35
|
+
* Increase `persistent_timeout` default to 65 seconds ([#3378])
|
36
|
+
* Raise an ArgumentError if no block given to hooks ([#3377])
|
37
|
+
* Don't set env['HTTP_VERSION'] for Rack > 3.1 ([#3711], [#3576])
|
38
|
+
* Runner.rb - remove `ruby_engine` method, deprecated Nov-2024 ([#3701])
|
39
|
+
* Config `preload_app!` is now the default for clustered mode ([#3297])
|
40
|
+
* Config instance must be `clamp`-d before reading any values ([#3297])
|
41
|
+
* Response headers set to lowercase ([#3704])
|
42
|
+
* Update minimum Ruby version to 3.0 ([#3698])
|
43
|
+
* Rename callback hooks ([#3438])
|
44
|
+
|
45
|
+
| Old hook name| New hook name|
|
46
|
+
|----------|----------|
|
47
|
+
| on_worker_boot | before_worker_boot |
|
48
|
+
| on_worker_shutdown | before_worker_shutdown |
|
49
|
+
| on_restart | before_restart |
|
50
|
+
| on_booted | after_booted |
|
51
|
+
| on_stopped | after_stopped |
|
52
|
+
| on_refork | before_refork |
|
53
|
+
| on_thread_start | before_thread_start |
|
54
|
+
| on_thread_exit | before_thread_exit |
|
55
|
+
| on_worker_fork | before_worker_fork |
|
56
|
+
|
57
|
+
* Features
|
58
|
+
* Fix long tail response problem with keepalive connections ([#3678]) (Previously released in 7.0.0.pre1, this was a high effort change)
|
59
|
+
* Introduce support for fiber-per-request. ([#3101])
|
60
|
+
* Add support for `rack.response_finished` ([#3681])
|
61
|
+
* Feature/support custom logger with request logs ([#3140])
|
62
|
+
|
63
|
+
* Bugfixes
|
64
|
+
* Fix error_logger inproperly logging `env[QUERY_STRING]` ([#3713], [#3625])
|
65
|
+
* Fix handling of invalid Transfer-Encoding header errors ([#3702])
|
66
|
+
* Fix socket leak on monitor wakeup `NoMethodError` in `Reactor#select_loop` ([#3696], [#3695])
|
67
|
+
* CI: puma_socket.rb fixup socket/request writes ([#3684])
|
68
|
+
* Warn when RUBY_MN_THREADS env var is set ([#3721])
|
69
|
+
* Improve the DSL `preload_app!` doc ([#3712])
|
70
|
+
* Fix the ability to focus individual tests ([#3705])
|
71
|
+
* Set env['rack.hijack'] to client.method(:full_hijack) ([#3073])
|
72
|
+
|
73
|
+
* Performance
|
74
|
+
* server.rb - initialize ivars `@reactor` and `@env_set_http_version` ([#3714])
|
75
|
+
|
76
|
+
* Refactor
|
77
|
+
* Simplify `Puma::DSL#process_hook` logic ([#3710])
|
78
|
+
* Dry up deprecation warnings and fix deprecation warnings when running CI. ([#3709], [#3708])
|
79
|
+
* Ensure and enforce that configs are loaded before options are accessed ([#3616])
|
80
|
+
|
81
|
+
## 7.0.0.pre1 / 2025-07-31
|
82
|
+
|
83
|
+
* Changed
|
84
|
+
* Fix long tail response problem with keepalive connections ([#3678])
|
85
|
+
|
1
86
|
## 6.6.1 / 2025-07-30
|
2
87
|
|
3
88
|
* Bugfixes
|
@@ -2160,12 +2245,53 @@ be added back in a future date when a java Puma::MiniSSL is added.
|
|
2160
2245
|
* Bugfixes
|
2161
2246
|
* Your bugfix goes here <Most recent on the top, like GitHub> (#Github Number)
|
2162
2247
|
|
2163
|
-
[#
|
2248
|
+
[#3703]:https://github.com/puma/puma/pull/3703 "PR by @marshall-lee, merged 2025-09-20"
|
2249
|
+
[#3742]:https://github.com/puma/puma/pull/3742 "PR by @kenballus, merged 2025-09-18"
|
2250
|
+
[#3754]:https://github.com/puma/puma/pull/3754 "PR by @byroot, merged 2025-09-18"
|
2251
|
+
[#3746]:https://github.com/puma/puma/pull/3746 "PR by @schneems, merged 2025-09-18"
|
2252
|
+
[#3740]:https://github.com/puma/puma/issues/3740 "Issue by @joshuay03, closed 2025-09-18"
|
2253
|
+
[#3748]:https://github.com/puma/puma/pull/3748 "PR by @MSP-Greg, merged 2025-09-14"
|
2254
|
+
[#3749]:https://github.com/puma/puma/pull/3749 "PR by @schneems, merged 2025-09-14"
|
2255
|
+
[#3736]:https://github.com/puma/puma/pull/3736 "PR by @MSP-Greg, merged 2025-09-08"
|
2256
|
+
[#3734]:https://github.com/puma/puma/issues/3734 "Issue by @espen, closed 2025-09-08"
|
2257
|
+
[#3729]:https://github.com/puma/puma/pull/3729 "PR by @bensheldon, merged 2025-09-08"
|
2258
|
+
[#3731]:https://github.com/puma/puma/pull/3731 "PR by @stanhu, merged 2025-09-06"
|
2259
|
+
[#3725]:https://github.com/puma/puma/pull/3725 "PR by @tannakartikey, merged 2025-09-05"
|
2260
|
+
[#3719]:https://github.com/puma/puma/pull/3719 "PR by @schneems, merged 2025-09-03"
|
2261
|
+
[#3378]:https://github.com/puma/puma/pull/3378 "PR by @shayonj, merged 2025-08-19"
|
2262
|
+
[#3377]:https://github.com/puma/puma/pull/3377 "PR by @joshuay03, merged 2025-08-12"
|
2263
|
+
[#3711]:https://github.com/puma/puma/pull/3711 "PR by @MSP-Greg, merged 2025-08-28"
|
2264
|
+
[#3576]:https://github.com/puma/puma/issues/3576 "Issue by @pdalberti, closed 2025-08-28"
|
2265
|
+
[#3701]:https://github.com/puma/puma/pull/3701 "PR by @MSP-Greg, merged 2025-08-26"
|
2266
|
+
[#3297]:https://github.com/puma/puma/pull/3297 "PR by @joshuay03, merged 2025-08-26"
|
2267
|
+
[#3704]:https://github.com/puma/puma/pull/3704 "PR by @schneems, merged 2025-08-25"
|
2268
|
+
[#3698]:https://github.com/puma/puma/pull/3698 "PR by @schneems, merged 2025-08-21"
|
2269
|
+
[#3438]:https://github.com/puma/puma/pull/3438 "PR by @tannakartikey, merged 2025-08-25"
|
2270
|
+
[#3678]:https://github.com/puma/puma/pull/3678 "PR by @MSP-Greg, merged 2025-07-31"
|
2271
|
+
[#3101]:https://github.com/puma/puma/pull/3101 "PR by @ioquatix, merged 2025-08-25"
|
2272
|
+
[#3681]:https://github.com/puma/puma/pull/3681 "PR by @byroot, merged 2025-08-15"
|
2273
|
+
[#3140]:https://github.com/puma/puma/pull/3140 "PR by @phyzical, merged 2025-08-12"
|
2274
|
+
[#3713]:https://github.com/puma/puma/pull/3713 "PR by @MSP-Greg, merged 2025-08-29"
|
2275
|
+
[#3625]:https://github.com/puma/puma/pull/3625 "PR by @bhooshiek-narendiran, closed 2025-08-29"
|
2276
|
+
[#3702]:https://github.com/puma/puma/pull/3702 "PR by @marshall-lee, merged 2025-08-25"
|
2277
|
+
[#3696]:https://github.com/puma/puma/pull/3696 "PR by @joshuay03, merged 2025-08-22"
|
2278
|
+
[#3695]:https://github.com/puma/puma/issues/3695 "Issue by @joshuay03, closed 2025-08-22"
|
2279
|
+
[#3684]:https://github.com/puma/puma/pull/3684 "PR by @MSP-Greg, merged 2025-08-02"
|
2280
|
+
[#3721]:https://github.com/puma/puma/pull/3721 "PR by @schneems, merged 2025-09-03"
|
2281
|
+
[#3712]:https://github.com/puma/puma/pull/3712 "PR by @joshuay03, merged 2025-08-28"
|
2282
|
+
[#3705]:https://github.com/puma/puma/pull/3705 "PR by @schneems, merged 2025-08-25"
|
2283
|
+
[#3073]:https://github.com/puma/puma/pull/3073 "PR by @MSP-Greg, merged 2025-08-12"
|
2284
|
+
[#3714]:https://github.com/puma/puma/pull/3714 "PR by @MSP-Greg, merged 2025-08-29"
|
2285
|
+
[#3710]:https://github.com/puma/puma/pull/3710 "PR by @joshuay03, merged 2025-08-28"
|
2286
|
+
[#3709]:https://github.com/puma/puma/pull/3709 "PR by @MSP-Greg, merged 2025-08-28"
|
2287
|
+
[#3708]:https://github.com/puma/puma/issues/3708 "Issue by @schneems, closed 2025-08-28"
|
2288
|
+
[#3616]:https://github.com/puma/puma/pull/3616 "PR by @joshuay03, merged 2025-08-25"
|
2289
|
+
[#3635]:https://github.com/puma/puma/pull/3635 "PR by @LevitatingBusinessMan, merged 2025-05-08"
|
2164
2290
|
[#3572]:https://github.com/puma/puma/pull/3572 "PR by @barthez, merged 2025-02-06"
|
2291
|
+
[#3601]:https://github.com/puma/puma/pull/3601 "PR by @joshuay03, merged 2025-01-31"
|
2165
2292
|
[#3586]:https://github.com/puma/puma/pull/3586 "PR by @MSP-Greg, merged 2025-02-03"
|
2166
2293
|
[#3598]:https://github.com/puma/puma/pull/3598 "PR by @joshuay03, merged 2025-01-31"
|
2167
|
-
[#
|
2168
|
-
[#3635]:https://github.com/puma/puma/pull/3635 "PR by @LevitatingBusinessMan, merged 2025-05-08"
|
2294
|
+
[#3680]:https://github.com/puma/puma/pull/3680 "PR by @byroot, merged 2025-07-31"
|
2169
2295
|
[#3570]:https://github.com/puma/puma/pull/3570 "PR by @mohamedhafez, merged 2024-12-30"
|
2170
2296
|
[#3567]:https://github.com/puma/puma/issues/3567 "Issue by @mohamedhafez, closed 2024-12-30"
|
2171
2297
|
[#3383]:https://github.com/puma/puma/pull/3383 "PR by @joshuay03, merged 2024-11-29"
|
@@ -2764,7 +2890,7 @@ be added back in a future date when a java Puma::MiniSSL is added.
|
|
2764
2890
|
[#1022]:https://github.com/puma/puma/issues/1022 "Issue by @AKovtunov, closed 2017-08-16"
|
2765
2891
|
[#958]:https://github.com/puma/puma/issues/958 "Issue by @lalitlogical, closed 2016-04-23"
|
2766
2892
|
[#782]:https://github.com/puma/puma/issues/782 "Issue by @Tonkpils, closed 2016-07-19"
|
2767
|
-
[#1010]:https://github.com/puma/puma/issues/1010 "Issue by @
|
2893
|
+
[#1010]:https://github.com/puma/puma/issues/1010 "Issue by @mirineumark, closed 2016-07-19"
|
2768
2894
|
[#959]:https://github.com/puma/puma/issues/959 "Issue by @mwpastore, closed 2016-04-22"
|
2769
2895
|
[#840]:https://github.com/puma/puma/issues/840 "Issue by @marisawallace, closed 2016-04-07"
|
2770
2896
|
[#1007]:https://github.com/puma/puma/pull/1007 "PR by @willnet, merged 2016-06-24"
|
data/README.md
CHANGED
@@ -124,7 +124,7 @@ For an in-depth discussion of the tradeoffs of thread and process count settings
|
|
124
124
|
|
125
125
|
In cluster mode, Puma can "preload" your application. This loads all the application code *prior* to forking. Preloading reduces total memory usage of your application via an operating system feature called [copy-on-write](https://en.wikipedia.org/wiki/Copy-on-write).
|
126
126
|
|
127
|
-
If the
|
127
|
+
If the number of workers is greater than 1 (and `--prune-bundler` has not been specified), preloading will be enabled by default. Otherwise, you can use the `--preload` flag from the command line:
|
128
128
|
|
129
129
|
```
|
130
130
|
$ puma -w 3 --preload
|
@@ -142,7 +142,7 @@ Preloading can’t be used with phased restart, since phased restart kills and r
|
|
142
142
|
|
143
143
|
#### Cluster mode hooks
|
144
144
|
|
145
|
-
When using
|
145
|
+
When using clustered mode, Puma's configuration DSL provides `before_fork` and `before_worker_boot`
|
146
146
|
hooks to run code when the master process forks and child workers are booted respectively.
|
147
147
|
|
148
148
|
It is recommended to use these hooks with `preload_app!`, otherwise constants loaded by your
|
@@ -154,16 +154,16 @@ before_fork do
|
|
154
154
|
# Add code to run inside the Puma master process before it forks a worker child.
|
155
155
|
end
|
156
156
|
|
157
|
-
|
157
|
+
before_worker_boot do
|
158
158
|
# Add code to run inside the Puma worker process after forking.
|
159
159
|
end
|
160
160
|
```
|
161
161
|
|
162
|
-
In addition, there is an `
|
162
|
+
In addition, there is an `before_refork` and `after_refork` hooks which are used only in [`fork_worker` mode](docs/fork_worker.md),
|
163
163
|
when the worker 0 child process forks a grandchild worker:
|
164
164
|
|
165
165
|
```ruby
|
166
|
-
|
166
|
+
before_refork do
|
167
167
|
# Used only when fork_worker mode is enabled. Add code to run inside the Puma worker 0
|
168
168
|
# child process before it forks a grandchild worker.
|
169
169
|
end
|
@@ -190,29 +190,29 @@ Therefore, we recommend the following:
|
|
190
190
|
|
191
191
|
1. If possible, do not establish any socket connections (HTTP, database connections, etc.)
|
192
192
|
inside Puma's master process when booting.
|
193
|
-
2. If (1) is not possible, use `before_fork` and `
|
193
|
+
2. If (1) is not possible, use `before_fork` and `before_refork` to disconnect the parent's socket
|
194
194
|
connections when forking, so that they are not accidentally copied to the child process.
|
195
|
-
3. Use `
|
195
|
+
3. Use `before_worker_boot` to restart any background threads on the forked child.
|
196
196
|
4. Use `after_refork` to restart any background threads on the parent.
|
197
197
|
|
198
198
|
#### Master process lifecycle hooks
|
199
199
|
|
200
|
-
Puma's configuration DSL provides master process lifecycle hooks `
|
200
|
+
Puma's configuration DSL provides master process lifecycle hooks `after_booted`, `before_restart`, and `after_stopped`
|
201
201
|
which may be used to specify code blocks to run on each event:
|
202
202
|
|
203
203
|
```ruby
|
204
204
|
# config/puma.rb
|
205
|
-
|
205
|
+
after_booted do
|
206
206
|
# Add code to run in the Puma master process after it boots,
|
207
207
|
# and also after a phased restart completes.
|
208
208
|
end
|
209
209
|
|
210
|
-
|
210
|
+
before_restart do
|
211
211
|
# Add code to run in the Puma master process when it receives
|
212
212
|
# a restart command but before it restarts.
|
213
213
|
end
|
214
214
|
|
215
|
-
|
215
|
+
after_stopped do
|
216
216
|
# Add code to run in the Puma master process when it receives
|
217
217
|
# a stop command but before it shuts down.
|
218
218
|
end
|
@@ -432,19 +432,6 @@ Some platforms do not support all Puma features.
|
|
432
432
|
* **Windows**: Cluster mode is not supported due to a lack of fork(2).
|
433
433
|
* **Kubernetes**: The way Kubernetes handles pod shutdowns interacts poorly with server processes implementing graceful shutdown, like Puma. See the [kubernetes section of the documentation](docs/kubernetes.md) for more details.
|
434
434
|
|
435
|
-
## Known Bugs
|
436
|
-
|
437
|
-
For MRI versions 2.2.7, 2.2.8, 2.2.9, 2.2.10, 2.3.4 and 2.4.1, you may see ```stream closed in another thread (IOError)```. It may be caused by a [Ruby bug](https://bugs.ruby-lang.org/issues/13632). It can be fixed with the gem https://rubygems.org/gems/stopgap_13632:
|
438
|
-
|
439
|
-
```ruby
|
440
|
-
if %w(2.2.7 2.2.8 2.2.9 2.2.10 2.3.4 2.4.1).include? RUBY_VERSION
|
441
|
-
begin
|
442
|
-
require 'stopgap_13632'
|
443
|
-
rescue LoadError
|
444
|
-
end
|
445
|
-
end
|
446
|
-
```
|
447
|
-
|
448
435
|
## Deployment
|
449
436
|
|
450
437
|
* Puma has support for Capistrano with an [external gem](https://github.com/seuros/capistrano-puma).
|
data/docs/fork_worker.md
CHANGED
@@ -24,13 +24,13 @@ The `fork_worker` option allows your application to be initialized only once for
|
|
24
24
|
|
25
25
|
### Usage Considerations
|
26
26
|
|
27
|
-
- `fork_worker` introduces new `
|
28
|
-
- When initially forking the parent process to the worker 0 child, `before_fork` will trigger on the parent process and `
|
29
|
-
- When forking the worker 0 child to grandchild workers, `
|
27
|
+
- `fork_worker` introduces new `before_refork` and `after_refork` configuration hooks. Note the following:
|
28
|
+
- When initially forking the parent process to the worker 0 child, `before_fork` will trigger on the parent process and `before_worker_boot` will trigger on the worker 0 child as normal.
|
29
|
+
- When forking the worker 0 child to grandchild workers, `before_refork` and `after_refork` will trigger on the worker 0 child, and `before_worker_boot` will trigger on each grandchild worker.
|
30
30
|
- For clarity, `before_fork` does not trigger on worker 0, and `after_refork` does not trigger on the grandchild.
|
31
31
|
- As a general migration guide:
|
32
|
-
- Copy any logic within your existing `before_fork` hook to the `
|
33
|
-
- Consider to copy logic from your `
|
32
|
+
- Copy any logic within your existing `before_fork` hook to the `before_refork` hook.
|
33
|
+
- Consider to copy logic from your `before_worker_boot` hook to the `after_refork` hook, if it is needed to reset the state of worker 0 after it forks.
|
34
34
|
|
35
35
|
### Limitations
|
36
36
|
|
data/docs/kubernetes.md
CHANGED
@@ -8,10 +8,11 @@ In general running Puma in Kubernetes works as-is, no special configuration is n
|
|
8
8
|
|
9
9
|
Assuming you already have a running cluster and docker image repository, you can run a simple Puma app with the following example Dockerfile and Deployment specification. These are meant as examples only and are deliberately very minimal to the point of skipping many options that are recommended for running in production, like healthchecks and envvar configuration with ConfigMaps. In general you should check the [Kubernetes documentation](https://kubernetes.io/docs/home/) and [Docker documentation](https://docs.docker.com/) for a more comprehensive overview of the available options.
|
10
10
|
|
11
|
-
A basic Dockerfile example:
|
11
|
+
A basic Dockerfile example:
|
12
|
+
|
12
13
|
```
|
13
|
-
FROM ruby:
|
14
|
-
RUN apk update && apk add build-base # and any other packages you need
|
14
|
+
FROM ruby:3.4.5-alpine # can be updated to newer ruby versions
|
15
|
+
RUN apk update && apk add build-base # and any other packages you need
|
15
16
|
|
16
17
|
# Only rebuild gem bundle if Gemfile changes
|
17
18
|
COPY Gemfile Gemfile.lock ./
|
@@ -26,6 +27,7 @@ CMD bundle exec rackup -o 0.0.0.0
|
|
26
27
|
```
|
27
28
|
|
28
29
|
A sample `deployment.yaml`:
|
30
|
+
|
29
31
|
```
|
30
32
|
---
|
31
33
|
apiVersion: apps/v1
|
@@ -47,7 +49,7 @@ spec:
|
|
47
49
|
image: <your image here>
|
48
50
|
ports:
|
49
51
|
- containerPort: 9292
|
50
|
-
```
|
52
|
+
```
|
51
53
|
|
52
54
|
## Graceful shutdown and pod termination
|
53
55
|
|
data/docs/restart.md
CHANGED
@@ -29,7 +29,7 @@ Any of the following will cause a Puma server to perform a hot restart:
|
|
29
29
|
|
30
30
|
* The newly started Puma process changes its current working directory to the directory specified by the `directory` option. If `directory` is set to symlink, this is automatically re-evaluated, so this mechanism can be used to upgrade the application.
|
31
31
|
* Only one version of the application is running at a time.
|
32
|
-
* `
|
32
|
+
* `before_restart` is invoked just before the server shuts down. This can be used to clean up resources (like long-lived database connections) gracefully. Since Ruby 2.0, it is not typically necessary to explicitly close file descriptors on restart. This is because any file descriptor opened by Ruby will have the `FD_CLOEXEC` flag set, meaning that file descriptors are closed on `exec`. `before_restart` is useful, though, if your application needs to perform any more graceful protocol-specific shutdown procedures before closing connections.
|
33
33
|
|
34
34
|
## Phased restart
|
35
35
|
|
@@ -59,7 +59,7 @@ Any of the following will cause a Puma server to perform a phased restart:
|
|
59
59
|
|
60
60
|
* When a phased restart begins, the Puma master process changes its current working directory to the directory specified by the `directory` option. If `directory` is set to symlink, this is automatically re-evaluated, so this mechanism can be used to upgrade the application.
|
61
61
|
* On a single server, it's possible that two versions of the application are running concurrently during a phased restart.
|
62
|
-
* `
|
62
|
+
* `before_restart` is not invoked
|
63
63
|
* Phased restarts can be slow for Puma clusters with many workers. Hot restarts often complete more quickly, but at the cost of increased latency during the restart.
|
64
64
|
* Phased restarts cannot be used to upgrade any gems loaded by the Puma master process, including `puma` itself, anything in `extra_runtime_dependencies`, or dependencies thereof. Upgrading other gems is safe.
|
65
65
|
* If you remove the gems from old releases as part of your deployment strategy, there are additional considerations. Do not put any gems into `extra_runtime_dependencies` that have native extensions or have dependencies that have native extensions (one common example is `puma_worker_killer` and its dependency on `ffi`). Workers will fail on boot during a phased restart. The underlying issue is recorded in [an issue on the rubygems project](https://github.com/rubygems/rubygems/issues/4004). Hot restarts are your only option here if you need these dependencies.
|
data/docs/signals.md
CHANGED
@@ -54,12 +54,12 @@ puma configuration file reloaded, if there is one
|
|
54
54
|
puma configuration file reloaded, if there is one
|
55
55
|
|
56
56
|
before_fork
|
57
|
-
|
57
|
+
before_worker_fork
|
58
58
|
after_worker_fork
|
59
59
|
|
60
60
|
Gemfile in context
|
61
61
|
|
62
|
-
|
62
|
+
before_worker_boot
|
63
63
|
|
64
64
|
Code of the app is loaded and running
|
65
65
|
```
|
@@ -67,18 +67,18 @@ Code of the app is loaded and running
|
|
67
67
|
### Send USR2
|
68
68
|
|
69
69
|
```
|
70
|
-
|
71
|
-
|
70
|
+
before_worker_shutdown
|
71
|
+
before_restart
|
72
72
|
|
73
73
|
puma configuration file reloaded, if there is one
|
74
74
|
|
75
75
|
before_fork
|
76
|
-
|
76
|
+
before_worker_fork
|
77
77
|
after_worker_fork
|
78
78
|
|
79
79
|
Gemfile in context
|
80
80
|
|
81
|
-
|
81
|
+
before_worker_boot
|
82
82
|
|
83
83
|
Code of the app is loaded and running
|
84
84
|
```
|
@@ -86,13 +86,13 @@ Code of the app is loaded and running
|
|
86
86
|
### Send USR1
|
87
87
|
|
88
88
|
```
|
89
|
-
|
90
|
-
|
89
|
+
before_worker_shutdown
|
90
|
+
before_worker_fork
|
91
91
|
after_worker_fork
|
92
92
|
|
93
93
|
Gemfile in context
|
94
94
|
|
95
|
-
|
95
|
+
before_worker_boot
|
96
96
|
|
97
97
|
Code of the app is loaded and running
|
98
98
|
```
|
data/docs/stats.md
CHANGED
@@ -65,7 +65,8 @@ When Puma runs in single mode, these stats are available at the top level. When
|
|
65
65
|
and is not used for any internal decisions, unlike `busy_theads`, which is usually a more useful stat.
|
66
66
|
* max_threads: the maximum number of threads Puma is configured to spool per worker
|
67
67
|
* requests_count: the number of requests this worker has served since starting
|
68
|
-
|
68
|
+
* reactor_max: the maximum observed number of requests held in Puma's "reactor" which is used for asyncronously buffering request bodies. This stat is reset on every call, so it's the maximum value observed since the last stat call.
|
69
|
+
* backlog_max: the maximum number of requests that have been fully buffered by the reactor and placed in a ready queue, but have not yet been picked up by a server thread. This stat is reset on every call, so it's the maximum value observed since the last stat call.
|
69
70
|
|
70
71
|
### cluster mode
|
71
72
|
|
data/ext/puma_http11/extconf.rb
CHANGED
@@ -52,29 +52,14 @@ unless ENV["PUMA_DISABLE_SSL"]
|
|
52
52
|
have_func "SSL_get1_peer_certificate" , ssl_h
|
53
53
|
|
54
54
|
puts ''
|
55
|
-
|
56
|
-
# Random.bytes available in Ruby 2.5 and later, Random::DEFAULT deprecated in 3.0
|
57
|
-
if Random.respond_to?(:bytes)
|
58
|
-
$defs.push "-DHAVE_RANDOM_BYTES"
|
59
|
-
puts "checking for Random.bytes... yes"
|
60
|
-
else
|
61
|
-
puts "checking for Random.bytes... no"
|
62
|
-
end
|
63
55
|
end
|
64
56
|
end
|
65
57
|
|
66
58
|
if ENV["PUMA_MAKE_WARNINGS_INTO_ERRORS"]
|
67
59
|
# Make all warnings into errors
|
68
60
|
# Except `implicit-fallthrough` since most failures comes from ragel state machine generated code
|
69
|
-
|
70
|
-
|
71
|
-
append_cflags '-Wno-implicit-fallthrough'
|
72
|
-
else
|
73
|
-
# flag may not exist on some platforms, -Werror may not be defined on some platforms, but
|
74
|
-
# works with all in current CI
|
75
|
-
$CFLAGS << " #{config_string('WERRORFLAG') || '-Werror'}"
|
76
|
-
$CFLAGS << ' -Wno-implicit-fallthrough'
|
77
|
-
end
|
61
|
+
append_cflags(config_string('WERRORFLAG') || '-Werror')
|
62
|
+
append_cflags '-Wno-implicit-fallthrough'
|
78
63
|
end
|
79
64
|
|
80
65
|
create_makefile("puma/puma_http11")
|
data/ext/puma_http11/mini_ssl.c
CHANGED
@@ -471,13 +471,8 @@ sslctx_initialize(VALUE self, VALUE mini_ssl_ctx) {
|
|
471
471
|
SSL_CTX_set_verify(ctx, NUM2INT(verify_mode), engine_verify_callback);
|
472
472
|
}
|
473
473
|
|
474
|
-
// Random.bytes available in Ruby 2.5 and later, Random::DEFAULT deprecated in 3.0
|
475
474
|
session_id_bytes = rb_funcall(
|
476
|
-
#ifdef HAVE_RANDOM_BYTES
|
477
475
|
rb_cRandom,
|
478
|
-
#else
|
479
|
-
rb_const_get(rb_cRandom, rb_intern_const("DEFAULT")),
|
480
|
-
#endif
|
481
476
|
rb_intern_const("bytes"),
|
482
477
|
1, ULL2NUM(SSL_MAX_SSL_SESSION_ID_LENGTH));
|
483
478
|
|
@@ -665,14 +660,29 @@ VALUE engine_shutdown(VALUE self) {
|
|
665
660
|
|
666
661
|
TypedData_Get_Struct(self, ms_conn, &engine_data_type, conn);
|
667
662
|
|
663
|
+
if (SSL_in_init(conn->ssl)) {
|
664
|
+
// Avoid "shutdown while in init" error
|
665
|
+
// See https://github.com/openssl/openssl/blob/openssl-3.5.2/ssl/ssl_lib.c#L2827-L2828
|
666
|
+
return Qtrue;
|
667
|
+
}
|
668
|
+
|
668
669
|
ERR_clear_error();
|
669
670
|
|
670
671
|
ok = SSL_shutdown(conn->ssl);
|
671
|
-
|
672
|
-
|
672
|
+
// See https://github.com/openssl/openssl/blob/openssl-3.5.2/ssl/ssl_lib.c#L2792-L2797
|
673
|
+
// for description of SSL_shutdown return values.
|
674
|
+
switch (ok) {
|
675
|
+
case 0:
|
676
|
+
// "close notify" alert is sent by us.
|
677
|
+
return Qfalse;
|
678
|
+
case 1:
|
679
|
+
// "close notify" alert was received from peer.
|
680
|
+
return Qtrue;
|
681
|
+
default:
|
682
|
+
raise_error(conn->ssl, ok);
|
673
683
|
}
|
674
684
|
|
675
|
-
return
|
685
|
+
return Qnil;
|
676
686
|
}
|
677
687
|
|
678
688
|
VALUE engine_init(VALUE self) {
|
@@ -109,6 +109,10 @@ public class Http11 extends RubyObject {
|
|
109
109
|
return (RubyClass)runtime.getModule("Puma").getConstant("HttpParserError");
|
110
110
|
}
|
111
111
|
|
112
|
+
private static boolean is_ows(int c) {
|
113
|
+
return c == ' ' || c == '\t';
|
114
|
+
}
|
115
|
+
|
112
116
|
public static void http_field(Ruby runtime, RubyHash req, ByteList buffer, int field, int flen, int value, int vlen) {
|
113
117
|
RubyString f;
|
114
118
|
IRubyObject v;
|
@@ -127,7 +131,11 @@ public class Http11 extends RubyObject {
|
|
127
131
|
}
|
128
132
|
}
|
129
133
|
|
130
|
-
while (vlen > 0 &&
|
134
|
+
while (vlen > 0 && is_ows(buffer.get(value + vlen - 1))) vlen--;
|
135
|
+
while (vlen > 0 && is_ows(buffer.get(value))) {
|
136
|
+
vlen--;
|
137
|
+
value++;
|
138
|
+
}
|
131
139
|
|
132
140
|
if (b.equals(CONTENT_LENGTH_BYTELIST) || b.equals(CONTENT_TYPE_BYTELIST)) {
|
133
141
|
f = RubyString.newString(runtime, b);
|
@@ -7,6 +7,7 @@
|
|
7
7
|
#define RSTRING_NOT_MODIFIED 1
|
8
8
|
|
9
9
|
#include "ruby.h"
|
10
|
+
#include "ruby/encoding.h"
|
10
11
|
#include "ext_help.h"
|
11
12
|
#include <assert.h>
|
12
13
|
#include <string.h>
|
@@ -48,8 +49,11 @@ static VALUE global_request_path;
|
|
48
49
|
#define VALIDATE_MAX_LENGTH(len, N) if(len > MAX_##N##_LENGTH) { rb_raise(eHttpParserError, MAX_##N##_LENGTH_ERR, len); }
|
49
50
|
|
50
51
|
/** Defines global strings in the init method. */
|
51
|
-
|
52
|
-
|
52
|
+
static inline void DEF_GLOBAL(VALUE *var, const char *cstr)
|
53
|
+
{
|
54
|
+
rb_global_variable(var);
|
55
|
+
*var = rb_enc_interned_str_cstr(cstr, rb_utf8_encoding());
|
56
|
+
}
|
53
57
|
|
54
58
|
/* Defines the maximum allowed lengths for various input elements.*/
|
55
59
|
#ifndef PUMA_REQUEST_URI_MAX_LENGTH
|
@@ -134,13 +138,13 @@ static void init_common_fields(void)
|
|
134
138
|
memcpy(tmp, HTTP_PREFIX, HTTP_PREFIX_LEN);
|
135
139
|
|
136
140
|
for(i = 0; i < ARRAY_SIZE(common_http_fields); cf++, i++) {
|
141
|
+
rb_global_variable(&cf->value);
|
137
142
|
if(cf->raw) {
|
138
143
|
cf->value = rb_str_new(cf->name, cf->len);
|
139
144
|
} else {
|
140
145
|
memcpy(tmp + HTTP_PREFIX_LEN, cf->name, cf->len + 1);
|
141
146
|
cf->value = rb_str_new(tmp, HTTP_PREFIX_LEN + cf->len);
|
142
147
|
}
|
143
|
-
rb_global_variable(&cf->value);
|
144
148
|
}
|
145
149
|
}
|
146
150
|
|
@@ -155,6 +159,10 @@ static VALUE find_common_field_value(const char *field, size_t flen)
|
|
155
159
|
return Qnil;
|
156
160
|
}
|
157
161
|
|
162
|
+
static int is_ows(const char c) {
|
163
|
+
return c == ' ' || c == '\t';
|
164
|
+
}
|
165
|
+
|
158
166
|
void http_field(puma_parser* hp, const char *field, size_t flen,
|
159
167
|
const char *value, size_t vlen)
|
160
168
|
{
|
@@ -181,7 +189,11 @@ void http_field(puma_parser* hp, const char *field, size_t flen,
|
|
181
189
|
f = rb_str_new(hp->buf, new_size);
|
182
190
|
}
|
183
191
|
|
184
|
-
while (vlen > 0 &&
|
192
|
+
while (vlen > 0 && is_ows(value[vlen - 1])) vlen--;
|
193
|
+
while (vlen > 0 && is_ows(value[0])) {
|
194
|
+
vlen--;
|
195
|
+
value++;
|
196
|
+
}
|
185
197
|
|
186
198
|
/* check for duplicate header */
|
187
199
|
v = rb_hash_aref(hp->request, f);
|
@@ -468,15 +480,15 @@ void Init_puma_http11(void)
|
|
468
480
|
VALUE mPuma = rb_define_module("Puma");
|
469
481
|
VALUE cHttpParser = rb_define_class_under(mPuma, "HttpParser", rb_cObject);
|
470
482
|
|
471
|
-
DEF_GLOBAL(
|
472
|
-
DEF_GLOBAL(
|
473
|
-
DEF_GLOBAL(
|
474
|
-
DEF_GLOBAL(
|
475
|
-
DEF_GLOBAL(
|
476
|
-
DEF_GLOBAL(
|
483
|
+
DEF_GLOBAL(&global_request_method, "REQUEST_METHOD");
|
484
|
+
DEF_GLOBAL(&global_request_uri, "REQUEST_URI");
|
485
|
+
DEF_GLOBAL(&global_fragment, "FRAGMENT");
|
486
|
+
DEF_GLOBAL(&global_query_string, "QUERY_STRING");
|
487
|
+
DEF_GLOBAL(&global_server_protocol, "SERVER_PROTOCOL");
|
488
|
+
DEF_GLOBAL(&global_request_path, "REQUEST_PATH");
|
477
489
|
|
478
|
-
eHttpParserError = rb_define_class_under(mPuma, "HttpParserError", rb_eStandardError);
|
479
490
|
rb_global_variable(&eHttpParserError);
|
491
|
+
eHttpParserError = rb_define_class_under(mPuma, "HttpParserError", rb_eStandardError);
|
480
492
|
|
481
493
|
rb_define_alloc_func(cHttpParser, HttpParser_alloc);
|
482
494
|
rb_define_method(cHttpParser, "initialize", HttpParser_init, 0);
|
data/lib/puma/binder.rb
CHANGED
@@ -5,7 +5,6 @@ require 'socket'
|
|
5
5
|
|
6
6
|
require_relative 'const'
|
7
7
|
require_relative 'util'
|
8
|
-
require_relative 'configuration'
|
9
8
|
|
10
9
|
module Puma
|
11
10
|
|
@@ -19,9 +18,9 @@ module Puma
|
|
19
18
|
|
20
19
|
RACK_VERSION = [1,6].freeze
|
21
20
|
|
22
|
-
def initialize(log_writer,
|
21
|
+
def initialize(log_writer, options, env: ENV)
|
23
22
|
@log_writer = log_writer
|
24
|
-
@
|
23
|
+
@options = options
|
25
24
|
@listeners = []
|
26
25
|
@inherited_fds = {}
|
27
26
|
@activated_sockets = {}
|
@@ -31,10 +30,10 @@ module Puma
|
|
31
30
|
@proto_env = {
|
32
31
|
"rack.version".freeze => RACK_VERSION,
|
33
32
|
"rack.errors".freeze => log_writer.stderr,
|
34
|
-
"rack.multithread".freeze =>
|
35
|
-
"rack.multiprocess".freeze =>
|
33
|
+
"rack.multithread".freeze => options[:max_threads] > 1,
|
34
|
+
"rack.multiprocess".freeze => options[:workers] >= 1,
|
36
35
|
"rack.run_once".freeze => false,
|
37
|
-
RACK_URL_SCHEME =>
|
36
|
+
RACK_URL_SCHEME => options[:rack_url_scheme],
|
38
37
|
"SCRIPT_NAME".freeze => env['SCRIPT_NAME'] || "",
|
39
38
|
|
40
39
|
# I'd like to set a default CONTENT_TYPE here but some things
|
@@ -44,7 +43,10 @@ module Puma
|
|
44
43
|
|
45
44
|
"QUERY_STRING".freeze => "",
|
46
45
|
SERVER_SOFTWARE => PUMA_SERVER_STRING,
|
47
|
-
GATEWAY_INTERFACE => CGI_VER
|
46
|
+
GATEWAY_INTERFACE => CGI_VER,
|
47
|
+
|
48
|
+
RACK_AFTER_REPLY => nil,
|
49
|
+
RACK_RESPONSE_FINISHED => nil,
|
48
50
|
}
|
49
51
|
|
50
52
|
@envs = {}
|
@@ -243,7 +245,7 @@ module Puma
|
|
243
245
|
cert_key.each do |v|
|
244
246
|
if params[v]&.start_with?('store:')
|
245
247
|
index = Integer(params.delete(v).split('store:').last)
|
246
|
-
params["#{v}_pem"] = @
|
248
|
+
params["#{v}_pem"] = @options[:store][index]
|
247
249
|
end
|
248
250
|
end
|
249
251
|
MiniSSL::ContextBuilder.new(params, @log_writer).context
|