puma 6.6.0 → 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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +147 -5
  3. data/README.md +18 -31
  4. data/docs/fork_worker.md +5 -5
  5. data/docs/kubernetes.md +6 -4
  6. data/docs/restart.md +2 -2
  7. data/docs/signals.md +11 -11
  8. data/docs/stats.md +2 -1
  9. data/docs/systemd.md +1 -1
  10. data/ext/puma_http11/extconf.rb +2 -17
  11. data/ext/puma_http11/mini_ssl.c +18 -8
  12. data/ext/puma_http11/org/jruby/puma/Http11.java +10 -2
  13. data/ext/puma_http11/puma_http11.c +23 -11
  14. data/lib/puma/binder.rb +10 -8
  15. data/lib/puma/cli.rb +3 -5
  16. data/lib/puma/client.rb +74 -36
  17. data/lib/puma/cluster/worker.rb +9 -10
  18. data/lib/puma/cluster/worker_handle.rb +36 -5
  19. data/lib/puma/cluster.rb +35 -22
  20. data/lib/puma/cluster_accept_loop_delay.rb +92 -0
  21. data/lib/puma/commonlogger.rb +3 -3
  22. data/lib/puma/configuration.rb +88 -43
  23. data/lib/puma/const.rb +9 -10
  24. data/lib/puma/control_cli.rb +6 -2
  25. data/lib/puma/detect.rb +2 -0
  26. data/lib/puma/dsl.rb +110 -90
  27. data/lib/puma/error_logger.rb +3 -1
  28. data/lib/puma/events.rb +25 -10
  29. data/lib/puma/io_buffer.rb +8 -4
  30. data/lib/puma/launcher/bundle_pruner.rb +1 -1
  31. data/lib/puma/launcher.rb +28 -29
  32. data/lib/puma/minissl.rb +0 -1
  33. data/lib/puma/plugin/systemd.rb +3 -3
  34. data/lib/puma/rack/urlmap.rb +1 -1
  35. data/lib/puma/reactor.rb +19 -4
  36. data/lib/puma/request.rb +45 -32
  37. data/lib/puma/runner.rb +8 -17
  38. data/lib/puma/server.rb +114 -68
  39. data/lib/puma/single.rb +5 -2
  40. data/lib/puma/thread_pool.rb +37 -81
  41. data/lib/puma/util.rb +0 -7
  42. data/lib/puma.rb +10 -0
  43. data/lib/rack/handler/puma.rb +2 -2
  44. data/tools/Dockerfile +3 -1
  45. metadata +5 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94e6b5d56525a92e2e279d59467572a254c7c03b9dc14a3e91ec5eba67b54620
4
- data.tar.gz: 55e78ab10a5d222cce09dc89a92fbbd15d8e8ae7abbec95ca309e2903f68bd97
3
+ metadata.gz: 13d2ebef5879f5ab45b75cadd20e4a72b643ff9f5e6af2cbcf69d655ec4475b8
4
+ data.tar.gz: 1ce847fac6f3e5f893814462b47792db32f1cb0960b9c8619d7ad26c4057bfec
5
5
  SHA512:
6
- metadata.gz: 750f9ec059b9710eb5ae739dc04ad600fff8386a40dc3ef83500189caacf8b7413d01eb60d751befd1aa077f3565e60617d13ceba8b9a0c29912abf410b700ff
7
- data.tar.gz: 1a56b1696333ae86e643bd045ebe83f6a1700ac5df948113a443326e867ce17bf3f4b7e05e01cda6b99605130a2b77ccf49d2ae153ad2e879971c7238d652548
6
+ metadata.gz: e67841b0a72c35c6667745e0aad11b152dbd46dc952b51ec811100281f8d93e45bc70fd16861b848918790b2eb0b0b290fa493f82beb0e4ed818abdffcb2f9fc
7
+ data.tar.gz: cecf1704d003e0f0299811a6c16310bb79fd7ee5ff21ce991bb2b82430f2d31e348a65b4054e57656255af10ac62489e4c4df889367a6c0b967d540522717ea7
data/History.md CHANGED
@@ -1,3 +1,98 @@
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
+
86
+ ## 6.6.1 / 2025-07-30
87
+
88
+ * Bugfixes
89
+ * Accept `to_path` to be `nil` on request bodies ([#3635])
90
+ * Fix single runner stats before the server start ([#3572])
91
+ * Fix incomplete worker boot state on refork ([#3601])
92
+ * Improve HttpParserError messages for better debugging ([#3586])
93
+ * Fix refork logs to distinguish from phased restarts ([#3598])
94
+ * Fix `rack.after_reply` so it doesn't interrupt chain on error ([#3680])
95
+
1
96
  ## 6.6.0 / 2025-01-29
2
97
 
3
98
  * Features
@@ -163,7 +258,7 @@
163
258
 
164
259
  * Features
165
260
  * Ability to supply a custom logger ([#2770], [#2511])
166
- * Warn when clustered-only hooks are defined in single mode ([#3089])
261
+ * Warn when cluster mode-only hooks are defined in single mode ([#3089])
167
262
  * Adds the on_booted event ([#2709])
168
263
 
169
264
  * Bugfixes
@@ -758,7 +853,7 @@ Each patchlevel release contains a separate security fix. We recommend simply up
758
853
  * Fix Java 8 support ([#1773])
759
854
  * Fix error `uninitialized constant Puma::Cluster` ([#1731])
760
855
  * Fix `not_token` being able to be set to true ([#1803])
761
- * Fix "Hang on SIGTERM with ruby 2.6 in clustered mode" (PR [#1741], [#1674], [#1720], [#1730], [#1755])
856
+ * Fix "Hang on SIGTERM with ruby 2.6 in cluster mode" (PR [#1741], [#1674], [#1720], [#1730], [#1755])
762
857
 
763
858
  ## 3.12.1 / 2019-03-19
764
859
 
@@ -1169,7 +1264,7 @@ Each patchlevel release contains a separate security fix. We recommend simply up
1169
1264
  * 4 minor features:
1170
1265
 
1171
1266
  * Listen to unix socket with provided backlog if any
1172
- * Improves the clustered stats to report worker stats
1267
+ * Improves the cluster mode stats to report worker stats
1173
1268
  * Pass the env to the lowlevel_error handler. Fixes [#854]
1174
1269
  * Treat path-like hosts as unix sockets. Fixes [#824]
1175
1270
 
@@ -1896,7 +1991,7 @@ The "clearly I don't have enough tests for the config" release.
1896
1991
 
1897
1992
  * 3 doc changes:
1898
1993
  * Add note about on_worker_boot hook
1899
- * Add some documentation for Clustered mode
1994
+ * Add some documentation for Cluster mode
1900
1995
  * Added quotes to /etc/puma.conf
1901
1996
 
1902
1997
  ## 2.0.1 / 2013-04-30
@@ -2150,6 +2245,53 @@ be added back in a future date when a java Puma::MiniSSL is added.
2150
2245
  * Bugfixes
2151
2246
  * Your bugfix goes here <Most recent on the top, like GitHub> (#Github Number)
2152
2247
 
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"
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"
2292
+ [#3586]:https://github.com/puma/puma/pull/3586 "PR by @MSP-Greg, merged 2025-02-03"
2293
+ [#3598]:https://github.com/puma/puma/pull/3598 "PR by @joshuay03, merged 2025-01-31"
2294
+ [#3680]:https://github.com/puma/puma/pull/3680 "PR by @byroot, merged 2025-07-31"
2153
2295
  [#3570]:https://github.com/puma/puma/pull/3570 "PR by @mohamedhafez, merged 2024-12-30"
2154
2296
  [#3567]:https://github.com/puma/puma/issues/3567 "Issue by @mohamedhafez, closed 2024-12-30"
2155
2297
  [#3383]:https://github.com/puma/puma/pull/3383 "PR by @joshuay03, merged 2024-11-29"
@@ -2748,7 +2890,7 @@ be added back in a future date when a java Puma::MiniSSL is added.
2748
2890
  [#1022]:https://github.com/puma/puma/issues/1022 "Issue by @AKovtunov, closed 2017-08-16"
2749
2891
  [#958]:https://github.com/puma/puma/issues/958 "Issue by @lalitlogical, closed 2016-04-23"
2750
2892
  [#782]:https://github.com/puma/puma/issues/782 "Issue by @Tonkpils, closed 2016-07-19"
2751
- [#1010]:https://github.com/puma/puma/issues/1010 "Issue by @mneumark, closed 2016-07-19"
2893
+ [#1010]:https://github.com/puma/puma/issues/1010 "Issue by @mirineumark, closed 2016-07-19"
2752
2894
  [#959]:https://github.com/puma/puma/issues/959 "Issue by @mwpastore, closed 2016-04-22"
2753
2895
  [#840]:https://github.com/puma/puma/issues/840 "Issue by @marisawallace, closed 2016-04-07"
2754
2896
  [#1007]:https://github.com/puma/puma/pull/1007 "PR by @willnet, merged 2016-06-24"
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # Puma: A Ruby Web Server Built For Parallelism
6
6
 
7
- [![Actions](https://github.com/puma/puma/workflows/Tests/badge.svg?branch=master)](https://github.com/puma/puma/actions?query=workflow%3ATests)
7
+ [![Actions](https://github.com/puma/puma/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/puma/puma/actions/workflows/tests.yml?query=branch%3Amaster)
8
8
  [![Code Climate](https://codeclimate.com/github/puma/puma.svg)](https://codeclimate.com/github/puma/puma)
9
9
  [![StackOverflow](https://img.shields.io/badge/stackoverflow-Puma-blue.svg)]( https://stackoverflow.com/questions/tagged/puma )
10
10
 
@@ -102,9 +102,9 @@ Puma will automatically scale the number of threads, from the minimum until it c
102
102
 
103
103
  Be aware that additionally Puma creates threads on its own for internal purposes (e.g. handling slow clients). So, even if you specify -t 1:1, expect around 7 threads created in your application.
104
104
 
105
- ### Clustered mode
105
+ ### Cluster mode
106
106
 
107
- Puma also offers "clustered mode". Clustered mode `fork`s workers from a master process. Each child process still has its own thread pool. You can tune the number of workers with the `-w` (or `--workers`) flag:
107
+ Puma also offers "cluster mode". Cluster mode `fork`s workers from a master process. Each child process still has its own thread pool. You can tune the number of workers with the `-w` (or `--workers`) flag:
108
108
 
109
109
  ```
110
110
  $ puma -t 8:32 -w 3
@@ -116,15 +116,15 @@ Or with the `WEB_CONCURRENCY` environment variable:
116
116
  $ WEB_CONCURRENCY=3 puma -t 8:32
117
117
  ```
118
118
 
119
- Note that threads are still used in clustered mode, and the `-t` thread flag setting is per worker, so `-w 2 -t 16:16` will spawn 32 threads in total, with 16 in each worker process.
119
+ Note that threads are still used in cluster mode, and the `-t` thread flag setting is per worker, so `-w 2 -t 16:16` will spawn 32 threads in total, with 16 in each worker process.
120
120
 
121
121
  If the `WEB_CONCURRENCY` environment variable is set to `"auto"` and the `concurrent-ruby` gem is available in your application, Puma will set the worker process count to the result of [available processors](https://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent.html#available_processor_count-class_method).
122
122
 
123
123
  For an in-depth discussion of the tradeoffs of thread and process count settings, [see our docs](https://github.com/puma/puma/blob/9282a8efa5a0c48e39c60d22ca70051a25df9f55/docs/kubernetes.md#workers-per-pod-and-other-config-issues).
124
124
 
125
- In clustered 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).
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 `WEB_CONCURRENCY` environment variable is set to a value > 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:
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
@@ -140,9 +140,9 @@ preload_app!
140
140
 
141
141
  Preloading can’t be used with phased restart, since phased restart kills and restarts workers one-by-one, and preloading copies the code of master into the workers.
142
142
 
143
- #### Clustered mode hooks
143
+ #### Cluster mode hooks
144
144
 
145
- When using clustered mode, Puma's configuration DSL provides `before_fork` and `on_worker_boot`
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
- on_worker_boot do
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 `on_refork` and `after_refork` hooks which are used only in [`fork_worker` mode](docs/fork_worker.md),
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
- on_refork do
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
@@ -176,7 +176,7 @@ after_refork do
176
176
  end
177
177
  ```
178
178
 
179
- Importantly, note the following considerations when Ruby forks a child process:
179
+ Importantly, note the following considerations when Ruby forks a child process:
180
180
 
181
181
  1. File descriptors such as network sockets **are** copied from the parent to the forked
182
182
  child process. Dual-use of the same sockets by parent and child will result in I/O conflicts
@@ -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 `on_refork` to disconnect the parent's socket
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 `on_worker_boot` to restart any background threads on the forked child.
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 `on_booted`, `on_restart`, and `on_stopped`
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
- on_booted do
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
- on_restart do
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
- on_stopped do
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 `on_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 `on_worker_boot` will trigger on the worker 0 child as normal.
29
- - When forking the worker 0 child to grandchild workers, `on_refork` and `after_refork` will trigger on the worker 0 child, and `on_worker_boot` will trigger on each grandchild worker.
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 `on_refork` hook.
33
- - Consider to copy logic from your `on_worker_boot` hook to the `after_refork` hook, if it is needed to reset the state of worker 0 after it forks.
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:2.5.1-alpine # can be updated to newer ruby versions
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
- * `on_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`. `on_restart` is useful, though, if your application needs to perform any more graceful protocol-specific shutdown procedures before closing connections.
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
- * `on_restart` is not invoked
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
@@ -17,13 +17,13 @@ $ ps aux | grep tail
17
17
  schneems 87152 0.0 0.0 2432772 492 s032 S+ 12:46PM 0:00.00 tail -f my.log
18
18
  ```
19
19
 
20
- You can send a signal in Ruby using the [Process module](https://ruby-doc.org/3.2.2/Process.html#method-c-kill):
20
+ You can send a signal in Ruby using the [Process module](https://docs.ruby-lang.org/en/master/Process.html#method-c-kill):
21
21
 
22
22
  ```
23
23
  $ irb
24
24
  > puts pid
25
25
  => 87152
26
- Process.detach(pid) # https://ruby-doc.org/3.2.2/Process.html#method-c-detach
26
+ Process.detach(pid) # https://docs.ruby-lang.org/en/master/Process.html#method-c-detach
27
27
  Process.kill("TERM", pid)
28
28
  ```
29
29
 
@@ -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
- on_worker_fork
57
+ before_worker_fork
58
58
  after_worker_fork
59
59
 
60
60
  Gemfile in context
61
61
 
62
- on_worker_boot
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
- on_worker_shutdown
71
- on_restart
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
- on_worker_fork
76
+ before_worker_fork
77
77
  after_worker_fork
78
78
 
79
79
  Gemfile in context
80
80
 
81
- on_worker_boot
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
- on_worker_shutdown
90
- on_worker_fork
89
+ before_worker_shutdown
90
+ before_worker_fork
91
91
  after_worker_fork
92
92
 
93
93
  Gemfile in context
94
94
 
95
- on_worker_boot
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/docs/systemd.md CHANGED
@@ -72,7 +72,7 @@ systemd and Puma also support socket activation, where systemd opens the
72
72
  listening socket(s) in advance and provides them to the Puma master process on
73
73
  startup. Among other advantages, this keeps listening sockets open across puma
74
74
  restarts and achieves graceful restarts, including when upgraded Puma, and is
75
- compatible with both clustered mode and application preload.
75
+ compatible with both cluster mode and application preload.
76
76
 
77
77
  **Note:** Any wrapper scripts which `exec`, or other indirections in `ExecStart`
78
78
  may result in activated socket file descriptors being closed before reaching the
@@ -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
- if respond_to?(:append_cflags, true) # Ruby 2.5 and later
70
- append_cflags(config_string('WERRORFLAG') || '-Werror')
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")
@@ -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
- if (ok == 0) {
672
- return Qfalse;
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 Qtrue;
685
+ return Qnil;
676
686
  }
677
687
 
678
688
  VALUE engine_init(VALUE self) {
@@ -29,7 +29,7 @@ public class Http11 extends RubyObject {
29
29
  public final static int MAX_REQUEST_URI_LENGTH = getConstLength("PUMA_REQUEST_URI_MAX_LENGTH", 1024 * 12);
30
30
  public final static String MAX_REQUEST_URI_LENGTH_ERR = "HTTP element REQUEST_URI is longer than the " + MAX_REQUEST_URI_LENGTH + " allowed length.";
31
31
  public final static int MAX_FRAGMENT_LENGTH = 1024;
32
- public final static String MAX_FRAGMENT_LENGTH_ERR = "HTTP element REQUEST_PATH is longer than the 1024 allowed length.";
32
+ public final static String MAX_FRAGMENT_LENGTH_ERR = "HTTP element FRAGMENT is longer than the 1024 allowed length.";
33
33
  public final static int MAX_REQUEST_PATH_LENGTH = getConstLength("PUMA_REQUEST_PATH_MAX_LENGTH", 8192);
34
34
  public final static String MAX_REQUEST_PATH_LENGTH_ERR = "HTTP element REQUEST_PATH is longer than the " + MAX_REQUEST_PATH_LENGTH + " allowed length.";
35
35
  public final static int MAX_QUERY_STRING_LENGTH = getConstLength("PUMA_QUERY_STRING_MAX_LENGTH", 10 * 1024);
@@ -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 && Character.isWhitespace(buffer.get(value + vlen - 1))) vlen--;
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);