puma 6.3.1-java → 6.4.1-java

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puma might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6f5e262555fc1a48fc5b142830e71c44508163d7a411374379e3b95cb9543161
4
- data.tar.gz: ca0ca73ded268f1d35b8e1dcd9f8b852a19dcc513bb2f103241f21a18bf5cb2a
3
+ metadata.gz: 303909622ccfa9f081111d7b046bfa52b8fe9fdd123591a40093b2943907a0ed
4
+ data.tar.gz: 30c160957bc8ceeef7a6f92496b7c585e8c33efa7f7e74cb29f3ffbd9d1aa417
5
5
  SHA512:
6
- metadata.gz: 97563d93043490539f1d265e209c2356bc5beb35f5e7da2f3a7bb5ebb5ae25b0e675cd374e267c9cb32be81d7fc8a132344968154e68b7d9b257e9c09498c129
7
- data.tar.gz: 628fbc77c3b36f5324e3a4baf57a9d445b7168c6e8751f4d37e7b0a6b0d20c2cae4311228c72562f3a4ff0b2c7edfb776e8e5477405688176c4378df8fa9fde0
6
+ metadata.gz: 9828cf04803dc2a84025567f5777dd43c9ffdaeb92b8731caf88ebd58560d4470984afc3653b3e69b3a8769e0dcf422833b5478f6ce3c9ed1a5b44d6b83ab46c
7
+ data.tar.gz: 4cf1e28a1707c35bf0efd914aacdc918e3698c21f740b8a8882c368102b7ba72cd0f4bbc6d2e05c325f39ac9796ce45b7727235b41d2cd95c77150990d477147
data/History.md CHANGED
@@ -1,6 +1,48 @@
1
+ ## 6.4.1 / 2024-01-03
2
+
3
+ * Bugfixes
4
+ * DSL#warn_if_in_single_mode - fixup when workers set via CLI ([#3256])
5
+ * Fix `idle-timeout` not working in cluster mode ([#3235], [#3228], [#3282], [#3283])
6
+ * Fix worker 0 timing out during phased restart ([#3225], [#2786])
7
+ * context_builder.rb - require openssl if verify_mode != 'none' ([#3179])
8
+ * Make puma cluster process suitable as PID 1 ([#3255])
9
+ * Improve Puma::NullIO consistency with real IO ([#3276])
10
+ * extconf.rb - fixup to detect openssl info in Ruby build ([#3271], [#3266])
11
+ * MiniSSL.java - set serialVersionUID, fix RaiseException deprecation ([#3270])
12
+ * dsl.rb - fix warn_if_in_single_mode when WEB_CONCURRENCY is set ([#3265], [#3264])
13
+
14
+ * Maintenance
15
+ * LOTS of test refactoring to make tests more stable and easier to write - thanks to @MSP-Greg!
16
+ * Fix bug in tests re: TestPuma::HOST4 ([#3254])
17
+ * Dockerfile for minimal repros: use Ruby 3.2, expect bundler installed ([#3245])
18
+ * fix define_method calls, use Symbol parameter instead of String ([#3293])
19
+
20
+ * Docs
21
+ * README.md - add the puma-acme plugin ([#3301])
22
+ * Remove `--keep-file-descriptors` flag from systemd docs ([#3248])
23
+ * Note symlink mechanism in restart documentation for hot restart ([#3298])
24
+
25
+ ## 6.4.0 / 2023-09-21
26
+
27
+ * Features
28
+ * on_thread_exit hook ([#2920])
29
+ * on_thread_start_hook ([#3195])
30
+ * Shutdown on idle ([#3209], [#2580])
31
+ * New error message when control server port taken ([#3204])
32
+
33
+ * Refactor
34
+ * Remove `Forwardable` dependency ([#3191], #3190)
35
+ * Update URLMap Regexp usage for Ruby v3.3 ([#3165])
36
+
37
+ * Bugfixes
38
+ * Bring the cert_pem: parameter into parity with the cert: parameter to ssl_bind. ([#3174])
39
+ * Fix using control server with IPv6 host ([#3181])
40
+ * control_cli.rb - add require_relative 'log_writer' ([#3187])
41
+ * Fix cases where fallback Rack response wasn't sent to the client ([#3094])
42
+
1
43
  ## 6.3.1 / 2023-08-18
2
44
 
3
- * Security
45
+ * Security
4
46
  * Address HTTP request smuggling vulnerabilities with zero-length Content Length header and trailer fields ([GHSA-68xg-gqqm-vgj8](https://github.com/puma/puma/security/advisories/GHSA-68xg-gqqm-vgj8))
5
47
 
6
48
  ## 6.3.0 / 2023-05-31
@@ -15,7 +57,7 @@
15
57
  * Handle malformed request path ([#3155], [#3148])
16
58
  * Misc lib file fixes - trapping additional errors, CI helper ([#3129])
17
59
  * Fixup req form data file upload with "r\n" line endings ([#3137])
18
- * Restore rack 1.6 compatibility Restore rack 1.6 compatibility ([#3156])
60
+ * Restore rack 1.6 compatibility ([#3156])
19
61
 
20
62
  * Refactor
21
63
  * const.rb - Update Puma::HTTP_STATUS_CODES ([#3162])
@@ -74,12 +116,12 @@
74
116
  * Refactor const.rb - freeze ([#3016])
75
117
 
76
118
  ## 6.0.1 / 2022-12-20
77
-
119
+
78
120
  * Bugfixes
79
121
  * Handle waking up a closed selector in Reactor#add ([#3005])
80
122
  * Fixup response processing, enumerable bodies ([#3004], [#3000])
81
123
  * Correctly close app body for all code paths ([#3002], [#2999])
82
- * Refactor
124
+ * Refactor
83
125
  * Add IOBuffer to Client, remove from ThreadPool thread instances ([#3013])
84
126
 
85
127
  ## 6.0.0 / 2022-10-14
@@ -108,12 +150,12 @@
108
150
  * Allow header values to be arrays (Rack 3) ([#2936], [#2931])
109
151
  * Export Puma/Ruby versions in /stats ([#2875])
110
152
  * Allow configuring request uri max length & request path max length ([#2840])
111
- * Add a couple of public accessors ([#2774])
153
+ * Add a couple of public accessors ([#2774])
112
154
  * Log entire backtrace when worker start fails ([#2891])
113
155
  * [jruby] Enable TLSv1.3 support ([#2886])
114
156
  * [jruby] support setting TLS protocols + rename ssl_cipher_list ([#2899])
115
157
  * [jruby] Support a truststore option ([#2849], [#2904], [#2884])
116
-
158
+
117
159
  * Bugfixes
118
160
  * Load the configuration before passing it to the binder ([#2897])
119
161
  * Do not raise error raised on HTTP methods we don't recognize or support, like CONNECT ([#2932], [#1441])
@@ -126,6 +168,16 @@
126
168
  * Ruby 3.2 will have native IO#wait_* methods, don't require io/wait ([#2903])
127
169
  * Various internal API refactorings ([#2942], [#2921], [#2922], [#2955])
128
170
 
171
+ ## 5.6.7 / 2023-08-18
172
+
173
+ * Security
174
+ * Address HTTP request smuggling vulnerabilities with zero-length Content Length header and trailer fields ([GHSA-68xg-gqqm-vgj8](https://github.com/puma/puma/security/advisories/GHSA-68xg-gqqm-vgj8))
175
+
176
+ ## 5.6.6 / 2023-06-21
177
+
178
+ * Bugfix
179
+ * Prevent loading with rack 3 ([#3166])
180
+
129
181
  ## 5.6.5 / 2022-08-23
130
182
 
131
183
  * Feature
@@ -2001,6 +2053,38 @@ be added back in a future date when a java Puma::MiniSSL is added.
2001
2053
  * Bugfixes
2002
2054
  * Your bugfix goes here <Most recent on the top, like GitHub> (#Github Number)
2003
2055
 
2056
+ [#3256]:https://github.com/puma/puma/pull/3256 "PR by @MSP-Greg, merged 2023-10-16"
2057
+ [#3235]:https://github.com/puma/puma/pull/3235 "PR by @joshuay03, merged 2023-10-03"
2058
+ [#3228]:https://github.com/puma/puma/issues/3228 "Issue by @davidalejandroaguilar, closed 2023-10-03"
2059
+ [#3282]:https://github.com/puma/puma/issues/3282 "Issue by @bensheldon, closed 2024-01-02"
2060
+ [#3283]:https://github.com/puma/puma/pull/3283 "PR by @joshuay03, merged 2024-01-02"
2061
+ [#3225]:https://github.com/puma/puma/pull/3225 "PR by @joshuay03, merged 2023-09-27"
2062
+ [#2786]:https://github.com/puma/puma/issues/2786 "Issue by @vitiokss, closed 2023-09-27"
2063
+ [#3179]:https://github.com/puma/puma/pull/3179 "PR by @MSP-Greg, merged 2023-09-26"
2064
+ [#3255]:https://github.com/puma/puma/pull/3255 "PR by @casperisfine, merged 2023-10-19"
2065
+ [#3276]:https://github.com/puma/puma/pull/3276 "PR by @casperisfine, merged 2023-11-16"
2066
+ [#3271]:https://github.com/puma/puma/pull/3271 "PR by @MSP-Greg, merged 2023-10-30"
2067
+ [#3266]:https://github.com/puma/puma/issues/3266 "Issue by @Dragonicity, closed 2023-10-30"
2068
+ [#3270]:https://github.com/puma/puma/pull/3270 "PR by @MSP-Greg, merged 2023-10-30"
2069
+ [#3265]:https://github.com/puma/puma/pull/3265 "PR by @MSP-Greg, merged 2023-10-25"
2070
+ [#3264]:https://github.com/puma/puma/issues/3264 "Issue by @dentarg, closed 2023-10-25"
2071
+ [#3254]:https://github.com/puma/puma/pull/3254 "PR by @casperisfine, merged 2023-10-11"
2072
+ [#3245]:https://github.com/puma/puma/pull/3245 "PR by @olleolleolle, merged 2023-10-02"
2073
+ [#3293]:https://github.com/puma/puma/pull/3293 "PR by @MSP-Greg, merged 2023-12-21"
2074
+ [#3301]:https://github.com/puma/puma/pull/3301 "PR by @benburkert, merged 2023-12-29"
2075
+ [#3248]:https://github.com/puma/puma/pull/3248 "PR by @dentarg, merged 2023-10-04"
2076
+ [#3298]:https://github.com/puma/puma/pull/3298 "PR by @til, merged 2023-12-26"
2077
+ [#2920]:https://github.com/puma/puma/pull/2920 "PR by @biinari, merged 2023-07-11"
2078
+ [#3195]:https://github.com/puma/puma/pull/3195 "PR by @binarygit, merged 2023-08-15"
2079
+ [#3209]:https://github.com/puma/puma/pull/3209 "PR by @joshuay03, merged 2023-09-04"
2080
+ [#2580]:https://github.com/puma/puma/issues/2580 "Issue by @schuetzm, closed 2023-09-04"
2081
+ [#3204]:https://github.com/puma/puma/pull/3204 "PR by @dhavalsingh, merged 2023-08-25"
2082
+ [#3191]:https://github.com/puma/puma/pull/3191 "PR by @MSP-Greg, merged 2023-08-31"
2083
+ [#3165]:https://github.com/puma/puma/pull/3165 "PR by @fallwith, merged 2023-06-06"
2084
+ [#3174]:https://github.com/puma/puma/pull/3174 "PR by @copiousfreetime, merged 2023-06-11"
2085
+ [#3181]:https://github.com/puma/puma/pull/3181 "PR by @MSP-Greg, merged 2023-06-23"
2086
+ [#3187]:https://github.com/puma/puma/pull/3187 "PR by @MSP-Greg, merged 2023-06-30"
2087
+ [#3094]:https://github.com/puma/puma/pull/3094 "PR by @Vuta, merged 2023-07-23"
2004
2088
  [#3106]:https://github.com/puma/puma/pull/3106 "PR by @MSP-Greg, merged 2023-05-29"
2005
2089
  [#3014]:https://github.com/puma/puma/issues/3014 "Issue by @kyledrake, closed 2023-05-29"
2006
2090
  [#3161]:https://github.com/puma/puma/pull/3161 "PR by @MSP-Greg, merged 2023-05-27"
@@ -2099,6 +2183,7 @@ be added back in a future date when a java Puma::MiniSSL is added.
2099
2183
  [#2921]:https://github.com/puma/puma/issues/2921 "Issue by @MSP-Greg, closed 2022-09-15"
2100
2184
  [#2922]:https://github.com/puma/puma/issues/2922 "Issue by @MSP-Greg, closed 2022-09-10"
2101
2185
  [#2955]:https://github.com/puma/puma/pull/2955 "PR by @cafedomancer, merged 2022-09-15"
2186
+ [#3166]:https://github.com/puma/puma/pull/3166 "PR by @JoeDupuis, merged 2023-06-08"
2102
2187
  [#2868]:https://github.com/puma/puma/pull/2868 "PR by @MSP-Greg, merged 2022-06-02"
2103
2188
  [#2866]:https://github.com/puma/puma/issues/2866 "Issue by @slondr, closed 2022-06-02"
2104
2189
  [#2883]:https://github.com/puma/puma/pull/2883 "PR by @MSP-Greg, merged 2022-06-02"
@@ -2125,7 +2210,7 @@ be added back in a future date when a java Puma::MiniSSL is added.
2125
2210
  [#2794]:https://github.com/puma/puma/pull/2794 "PR by @johnnyshields, merged 2022-01-10"
2126
2211
  [#2759]:https://github.com/puma/puma/pull/2759 "PR by @ob-stripe, merged 2021-12-11"
2127
2212
  [#2731]:https://github.com/puma/puma/pull/2731 "PR by @baelter, merged 2021-11-02"
2128
- [#2341]:https://github.com/puma/puma/issues/2341 "Issue by @cjlarose, opened 2020-08-18"
2213
+ [#2341]:https://github.com/puma/puma/issues/2341 "Issue by @cjlarose, closed 2023-07-23"
2129
2214
  [#2728]:https://github.com/puma/puma/pull/2728 "PR by @dalibor, merged 2021-10-31"
2130
2215
  [#2733]:https://github.com/puma/puma/pull/2733 "PR by @ob-stripe, merged 2021-12-12"
2131
2216
  [#2807]:https://github.com/puma/puma/pull/2807 "PR by @MSP-Greg, merged 2022-01-25"
@@ -2173,7 +2258,7 @@ be added back in a future date when a java Puma::MiniSSL is added.
2173
2258
  [#2563]:https://github.com/puma/puma/pull/2563 "PR by @MSP-Greg, merged 2021-03-06"
2174
2259
  [#2504]:https://github.com/puma/puma/issues/2504 "Issue by @fsateler, closed 2021-03-06"
2175
2260
  [#2591]:https://github.com/puma/puma/pull/2591 "PR by @MSP-Greg, merged 2021-05-05"
2176
- [#2572]:https://github.com/puma/puma/issues/2572 "Issue by @josefbilendo, closed 2021-05-05"
2261
+ [#2572]:https://github.com/puma/puma/issues/2572 "Issue by @josef-krabath, closed 2021-05-05"
2177
2262
  [#2613]:https://github.com/puma/puma/pull/2613 "PR by @smcgivern, merged 2021-04-27"
2178
2263
  [#2605]:https://github.com/puma/puma/pull/2605 "PR by @pascalbetz, merged 2021-04-26"
2179
2264
  [#2584]:https://github.com/puma/puma/issues/2584 "Issue by @kaorihinata, closed 2021-04-26"
@@ -2489,7 +2574,7 @@ be added back in a future date when a java Puma::MiniSSL is added.
2489
2574
  [#1110]:https://github.com/puma/puma/pull/1110 "PR by @montdidier, merged 2016-12-12"
2490
2575
  [#1135]:https://github.com/puma/puma/pull/1135 "PR by @jkraemer, merged 2016-11-19"
2491
2576
  [#1081]:https://github.com/puma/puma/pull/1081 "PR by @frodsan, merged 2016-09-08"
2492
- [#1138]:https://github.com/puma/puma/pull/1138 "PR by @steakknife, merged 2016-12-13"
2577
+ [#1138]:https://github.com/puma/puma/pull/1138 "PR by @skull-squadron, merged 2016-12-13"
2493
2578
  [#1118]:https://github.com/puma/puma/pull/1118 "PR by @hiroara, merged 2016-11-20"
2494
2579
  [#1075]:https://github.com/puma/puma/issues/1075 "Issue by @pvalena, closed 2016-09-06"
2495
2580
  [#932]:https://github.com/puma/puma/issues/932 "Issue by @everplays, closed 2016-07-24"
data/README.md CHANGED
@@ -12,11 +12,15 @@ Puma is a **simple, fast, multi-threaded, and highly parallel HTTP 1.1 server fo
12
12
 
13
13
  ## Built For Speed &amp; Parallelism
14
14
 
15
- Puma processes requests using a C-optimized Ragel extension (inherited from Mongrel) that provides fast, accurate HTTP 1.1 protocol parsing in a portable way. Puma then serves the request using a thread pool. Each request is served in a separate thread, so truly parallel Ruby implementations (JRuby, Rubinius) will use all available CPU cores.
15
+ Puma is a server for [Rack](https://github.com/rack/rack)-powered HTTP applications written in Ruby. It is:
16
+ * **Multi-threaded**. Each request is served in a separate thread. This helps you serve more requests per second with less memory use.
17
+ * **Multi-process**. "Pre-forks" in cluster mode, using less memory per-process thanks to copy-on-write memory.
18
+ * **Standalone**. With SSL support, zero-downtime rolling restarts and a built-in request bufferer, you can deploy Puma without any reverse proxy.
19
+ * **Battle-tested**. Our HTTP parser is inherited from Mongrel and has over 15 years of production use. Puma is currently the most popular Ruby webserver, and is the default server for Ruby on Rails.
16
20
 
17
21
  Originally designed as a server for [Rubinius](https://github.com/rubinius/rubinius), Puma also works well with Ruby (MRI) and JRuby.
18
22
 
19
- On MRI, there is a Global VM Lock (GVL) that ensures only one thread can run Ruby code at a time. But if you're doing a lot of blocking IO (such as HTTP calls to external APIs like Twitter), Puma still improves MRI's throughput by allowing IO waiting to be done in parallel.
23
+ On MRI, there is a Global VM Lock (GVL) that ensures only one thread can run Ruby code at a time. But if you're doing a lot of blocking IO (such as HTTP calls to external APIs like Twitter), Puma still improves MRI's throughput by allowing IO waiting to be done in parallel. Truly parallel Ruby implementations (TruffleRuby, JRuby) don't have this limitation.
20
24
 
21
25
  ## Quick Start
22
26
 
@@ -114,6 +118,8 @@ $ WEB_CONCURRENCY=3 puma -t 8:32
114
118
 
115
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.
116
120
 
121
+ 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).
122
+
117
123
  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).
118
124
 
119
125
  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:
@@ -211,29 +217,32 @@ Puma supports the [`localhost`] gem for self-signed certificates. This is partic
211
217
 
212
218
  Puma automatically configures SSL when the [`localhost`] gem is loaded in a `development` environment:
213
219
 
220
+ Add the gem to your Gemfile:
214
221
  ```ruby
215
- # Add the gem to your Gemfile
216
222
  group(:development) do
217
223
  gem 'localhost'
218
224
  end
225
+ ```
219
226
 
220
- # And require it implicitly using bundler
227
+ And require it implicitly using bundler:
228
+ ```ruby
221
229
  require "bundler"
222
230
  Bundler.require(:default, ENV["RACK_ENV"].to_sym)
231
+ ```
223
232
 
224
- # Alternatively, you can require the gem in config.ru:
225
- require './app'
233
+ Alternatively, you can require the gem in your configuration file, either `config/puma/development.rb`, `config/puma.rb`, or set via the `-C` cli option:
234
+ ```ruby
226
235
  require 'localhost'
227
- run Sinatra::Application
236
+ # configuration methods (from Puma::DSL) as needed
228
237
  ```
229
238
 
230
239
  Additionally, Puma must be listening to an SSL socket:
231
240
 
232
241
  ```shell
233
- $ puma -b 'ssl://localhost:9292' config.ru
242
+ $ puma -b 'ssl://localhost:9292' -C config/use_local_host.rb
234
243
 
235
244
  # The following options allow you to reach Puma over HTTP as well:
236
- $ puma -b ssl://localhost:9292 -b tcp://localhost:9393 config.ru
245
+ $ puma -b ssl://localhost:9292 -b tcp://localhost:9393 -C config/use_local_host.rb
237
246
  ```
238
247
 
239
248
  [`localhost`]: https://github.com/socketry/localhost
@@ -401,6 +410,7 @@ Community guides:
401
410
  * [puma-plugin-statsd](https://github.com/yob/puma-plugin-statsd) — send Puma metrics to statsd
402
411
  * [puma-plugin-systemd](https://github.com/sj26/puma-plugin-systemd) — deeper integration with systemd for notify, status and watchdog. Puma 5.1.0 integrated notify and watchdog, which probably conflicts with this plugin. Puma 6.1.0 added status support which obsoletes the plugin entirely.
403
412
  * [puma-plugin-telemetry](https://github.com/babbel/puma-plugin-telemetry) - telemetry plugin for Puma offering various targets to publish
413
+ * [puma-acme](https://github.com/anchordotdev/puma-acme) - automatic SSL/HTTPS certificate provisioning and setup
404
414
 
405
415
  ### Monitoring
406
416
 
data/docs/kubernetes.md CHANGED
@@ -64,3 +64,15 @@ There is a subtle race condition between step 2 and 3: The replication controlle
64
64
  The way Kubernetes works this way, rather than handling step 2 synchronously, is due to the CAP theorem: in a distributed system there is no way to guarantee that any message will arrive promptly. In particular, waiting for all Service controllers to report back might get stuck for an indefinite time if one of them has already been terminated or if there has been a net split. A way to work around this is to add a sleep to the pre-stop hook of the same time as the `terminationGracePeriodSeconds` time. This will allow the Puma process to keep serving new requests during the entire grace period, although it will no longer receive new requests after all Service controllers have propagated the removal of the pod from their endpoint lists. Then, after `terminationGracePeriodSeconds`, the pod receives `SIGKILL` and closes down. If your process can't handle SIGKILL properly, for example because it needs to release locks in different services, you can also sleep for a shorter period (and/or increase `terminationGracePeriodSeconds`) as long as the time slept is longer than the time that your Service controllers take to propagate the pod removal. The downside of this workaround is that all pods will take at minimum the amount of time slept to shut down and this will increase the time required for your rolling deploy.
65
65
 
66
66
  More discussions and links to relevant articles can be found in https://github.com/puma/puma/issues/2343.
67
+
68
+ ## Workers Per Pod, and Other Config Issues
69
+
70
+ With containerization, you will have to make a decision about how "big" to make each pod. Should you run 2 pods with 50 workers each? 25 pods, each with 4 workers? 100 pods, with each Puma running in single mode? Each scenario represents the same total amount of capacity (100 Puma processes that can respond to requests), but there are tradeoffs to make.
71
+
72
+ * Worker counts should be somewhere between 4 and 32 in most cases. You want more than 4 in order to minimize time spent in request queueing for a free Puma worker, but probably less than ~32 because otherwise autoscaling is working in too large of an increment or they probably won't fit very well into your nodes. In any queueing system, queue time is proportional to 1/n, where n is the number of things pulling from the queue. Each pod will have its own request queue (i.e., the socket backlog). If you have 4 pods with 1 worker each (4 request queues), wait times are, proportionally, about 4 times higher than if you had 1 pod with 4 workers (1 request queue).
73
+ * Unless you have a very I/O-heavy application (50%+ time spent waiting on IO), use the default thread count (5 for MRI). Using higher numbers of threads with low I/O wait (<50%) will lead to additional request queueing time (latency!) and additional memory usage.
74
+ * More processes per pod reduces memory usage per process, because of copy-on-write memory and because the cost of the single master process is "amortized" over more child processes.
75
+ * Don't run less than 4 processes per pod if you can. Low numbers of processes per pod will lead to high request queueing, which means you will have to run more pods.
76
+ * If multithreaded, allocate 1 CPU per worker. If single threaded, allocate 0.75 cpus per worker. Most web applications spend about 25% of their time in I/O - but when you're running multi-threaded, your Puma process will have higher CPU usage and should be able to fully saturate a CPU core.
77
+ * Most Puma processes will use about ~512MB-1GB per worker, and about 1GB for the master process. However, you probably shouldn't bother with setting memory limits lower than around 2GB per process, because most places you are deploying will have 2GB of RAM per CPU. A sensible memory limit for a Puma configuration of 4 child workers might be something like 8 GB (1 GB for the master, 7GB for the 4 children).
78
+
data/docs/restart.md CHANGED
@@ -27,6 +27,7 @@ Any of the following will cause a Puma server to perform a hot restart:
27
27
 
28
28
  ### Additional notes
29
29
 
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.
30
31
  * Only one version of the application is running at a time.
31
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
33
 
data/docs/systemd.md CHANGED
@@ -51,7 +51,7 @@ ExecStart=/<FULLPATH>/bin/puma -C <YOUR_APP_PATH>/puma.rb
51
51
  # Variant: Rails start.
52
52
  # ExecStart=/<FULLPATH>/bin/puma -C <YOUR_APP_PATH>/config/puma.rb ../config.ru
53
53
 
54
- # Variant: Use `bundle exec --keep-file-descriptors puma` instead of binstub
54
+ # Variant: Use `bundle exec puma` instead of binstub
55
55
  # Variant: Specify directives inline.
56
56
  # ExecStart=/<FULLPATH>/puma -b tcp://0.0.0.0:9292 -b ssl://0.0.0.0:9293?key=key.pem&cert=cert.pem
57
57
 
@@ -76,9 +76,7 @@ compatible with both clustered 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
79
- puma master process. For example, if using `bundle exec`, pass the
80
- `--keep-file-descriptors` flag. `bundle exec` can be avoided by using a `puma`
81
- executable generated by `bundle binstubs puma`. This is tracked in [#1499].
79
+ puma master process.
82
80
 
83
81
  **Note:** Socket activation doesn't currently work on JRuby. This is tracked in
84
82
  [#1367].
@@ -10,7 +10,11 @@ end
10
10
 
11
11
  unless ENV["PUMA_DISABLE_SSL"]
12
12
  # don't use pkg_config('openssl') if '--with-openssl-dir' is used
13
- has_openssl_dir = dir_config('openssl').any?
13
+ # also looks within the Ruby build for directory info
14
+ has_openssl_dir = dir_config('openssl').any? ||
15
+ RbConfig::CONFIG['configure_args']&.include?('openssl') ||
16
+ Dir.exist?("#{RbConfig::TOPDIR}/src/main/c/openssl") # TruffleRuby
17
+
14
18
  found_pkg_config = !has_openssl_dir && pkg_config('openssl')
15
19
 
16
20
  found_ssl = if !$mingw && found_pkg_config
@@ -36,6 +36,12 @@ void raise_file_error(const char* caller, const char *filename) {
36
36
  rb_raise(eError, "%s: error in file '%s': %s", caller, filename, ERR_error_string(ERR_get_error(), NULL));
37
37
  }
38
38
 
39
+ NORETURN(void raise_param_error(const char* caller, const char *param));
40
+
41
+ void raise_param_error(const char* caller, const char *param) {
42
+ rb_raise(eError, "%s: error with parameter '%s': %s", caller, param, ERR_error_string(ERR_get_error(), NULL));
43
+ }
44
+
39
45
  void engine_free(void *ptr) {
40
46
  ms_conn *conn = ptr;
41
47
  ms_cert_buf* cert_buf = (ms_cert_buf*)SSL_get_app_data(conn->ssl);
@@ -226,7 +232,7 @@ sslctx_initialize(VALUE self, VALUE mini_ssl_ctx) {
226
232
  VALUE key, cert, ca, verify_mode, ssl_cipher_filter, no_tlsv1, no_tlsv1_1,
227
233
  verification_flags, session_id_bytes, cert_pem, key_pem, key_password_command, key_password;
228
234
  BIO *bio;
229
- X509 *x509;
235
+ X509 *x509 = NULL;
230
236
  EVP_PKEY *pkey;
231
237
  pem_password_cb *password_cb = NULL;
232
238
  const char *password = NULL;
@@ -298,16 +304,65 @@ sslctx_initialize(VALUE self, VALUE mini_ssl_ctx) {
298
304
  }
299
305
 
300
306
  if (!NIL_P(cert_pem)) {
307
+ X509 *ca = NULL;
308
+ unsigned long err;
309
+
301
310
  bio = BIO_new(BIO_s_mem());
302
311
  BIO_puts(bio, RSTRING_PTR(cert_pem));
312
+
313
+ /**
314
+ * Much of this pulled as a simplified version of the `use_certificate_chain_file` method
315
+ * from openssl's `ssl_rsa.c` file.
316
+ */
317
+
318
+ /* first read the cert as the first item in the pem file */
303
319
  x509 = PEM_read_bio_X509(bio, NULL, NULL, NULL);
320
+ if (NULL == x509) {
321
+ BIO_free_all(bio);
322
+ raise_param_error("PEM_read_bio_X509", "cert_pem");
323
+ }
304
324
 
305
- if (SSL_CTX_use_certificate(ctx, x509) != 1) {
306
- BIO_free(bio);
307
- raise_file_error("SSL_CTX_use_certificate", RSTRING_PTR(cert_pem));
325
+ /* Add the cert to the context */
326
+ /* 1 is success - otherwise check the error codes */
327
+ if (1 != SSL_CTX_use_certificate(ctx, x509)) {
328
+ BIO_free_all(bio);
329
+ raise_param_error("SSL_CTX_use_certificate", "cert_pem");
330
+ }
331
+
332
+ X509_free(x509); /* no longer need our reference */
333
+
334
+ /* Now lets load up the rest of the certificate chain */
335
+ /* 1 is success 0 is error */
336
+ if (0 == SSL_CTX_clear_chain_certs(ctx)) {
337
+ BIO_free_all(bio);
338
+ raise_param_error("SSL_CTX_clear_chain_certs","cert_pem");
339
+ }
340
+
341
+ while (1) {
342
+ ca = PEM_read_bio_X509(bio, NULL, NULL, NULL);
343
+
344
+ if (NULL == ca) {
345
+ break;
346
+ }
347
+
348
+ if (0 == SSL_CTX_add0_chain_cert(ctx, ca)) {
349
+ BIO_free_all(bio);
350
+ raise_param_error("SSL_CTX_add0_chain_cert","cert_pem");
351
+ }
352
+ /* don't free ca - its now owned by the context */
353
+ }
354
+
355
+ /* ca is NULL - so its either the end of the file or an error */
356
+ err = ERR_peek_last_error();
357
+
358
+ /* If its the end of the file - then we are done, in any case free the bio */
359
+ BIO_free_all(bio);
360
+
361
+ if ((ERR_GET_LIB(err) == ERR_LIB_PEM) && (ERR_GET_REASON(err) == PEM_R_NO_START_LINE)) {
362
+ ERR_clear_error();
363
+ } else {
364
+ raise_param_error("PEM_read_bio_X509","cert_pem");
308
365
  }
309
- X509_free(x509);
310
- BIO_free(bio);
311
366
  }
312
367
 
313
368
  if (!NIL_P(key_pem)) {
@@ -491,7 +546,7 @@ NORETURN(void raise_error(SSL* ssl, int result));
491
546
 
492
547
  void raise_error(SSL* ssl, int result) {
493
548
  char buf[512];
494
- char msg[512];
549
+ char msg[768];
495
550
  const char* err_str;
496
551
  int err = errno;
497
552
  int mask = 4095;
@@ -749,6 +804,10 @@ void Init_mini_ssl(VALUE puma) {
749
804
 
750
805
  rb_define_method(eng, "init?", engine_init, 0);
751
806
 
807
+ /* @!attribute [r] peercert
808
+ * Returns `nil` when `MiniSSL::Context#verify_mode` is set to `VERIFY_NONE`.
809
+ * @return [String, nil] DER encoded cert
810
+ */
752
811
  rb_define_method(eng, "peercert", engine_peercert, 0);
753
812
 
754
813
  rb_define_method(eng, "ssl_vers_st", engine_ssl_vers_st, 0);
@@ -47,6 +47,7 @@ import static javax.net.ssl.SSLEngineResult.Status;
47
47
  import static javax.net.ssl.SSLEngineResult.HandshakeStatus;
48
48
 
49
49
  public class MiniSSL extends RubyObject { // MiniSSL::Engine
50
+ private static final long serialVersionUID = -6903439483039141234L;
50
51
  private static ObjectAllocator ALLOCATOR = new ObjectAllocator() {
51
52
  public IRubyObject allocate(Ruby runtime, RubyClass klass) {
52
53
  return new MiniSSL(runtime, klass);
@@ -500,7 +501,7 @@ public class MiniSSL extends RubyObject { // MiniSSL::Engine
500
501
  }
501
502
 
502
503
  private static RaiseException newError(Ruby runtime, RubyClass errorClass, String message, Throwable cause) {
503
- RaiseException ex = new RaiseException(runtime, errorClass, message, true);
504
+ RaiseException ex = RaiseException.from(runtime, errorClass, message);
504
505
  ex.initCause(cause);
505
506
  return ex;
506
507
  }
data/lib/puma/binder.rb CHANGED
@@ -330,7 +330,7 @@ module Puma
330
330
  return
331
331
  end
332
332
 
333
- host = host[1..-2] if host and host[0..0] == '['
333
+ host = host[1..-2] if host&.start_with? '['
334
334
  tcp_server = TCPServer.new(host, port)
335
335
 
336
336
  if optimize_for_latency
@@ -364,7 +364,7 @@ module Puma
364
364
  return
365
365
  end
366
366
 
367
- host = host[1..-2] if host[0..0] == '['
367
+ host = host[1..-2] if host&.start_with? '['
368
368
  s = TCPServer.new(host, port)
369
369
  if optimize_for_latency
370
370
  s.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
data/lib/puma/cli.rb CHANGED
@@ -144,6 +144,10 @@ module Puma
144
144
  $LOAD_PATH.unshift(*arg.split(':'))
145
145
  end
146
146
 
147
+ o.on "--idle-timeout SECONDS", "Number of seconds until the next request before automatic shutdown" do |arg|
148
+ user_config.idle_timeout arg
149
+ end
150
+
147
151
  o.on "-p", "--port PORT", "Define the TCP port to bind to",
148
152
  "Use -b for more advanced options" do |arg|
149
153
  user_config.bind "tcp://#{Configuration::DEFAULTS[:tcp_host]}:#{arg}"
data/lib/puma/client.rb CHANGED
@@ -11,7 +11,6 @@ end
11
11
  require_relative 'detect'
12
12
  require_relative 'io_buffer'
13
13
  require 'tempfile'
14
- require 'forwardable'
15
14
 
16
15
  if Puma::IS_JRUBY
17
16
  # We have to work around some OpenSSL buffer/io-readiness bugs
@@ -62,7 +61,6 @@ module Puma
62
61
  EmptyBody = NullIO.new
63
62
 
64
63
  include Puma::Const
65
- extend Forwardable
66
64
 
67
65
  def initialize(io, env=nil)
68
66
  @io = io
@@ -111,7 +109,10 @@ module Puma
111
109
 
112
110
  attr_accessor :remote_addr_header, :listener
113
111
 
114
- def_delegators :@io, :closed?
112
+ # Remove in Puma 7?
113
+ def closed?
114
+ @to_io.closed?
115
+ end
115
116
 
116
117
  # Test to see if io meets a bare minimum of functioning, @to_io needs to be
117
118
  # used for MiniSSL::Socket