puma 5.5.0 → 5.6.7
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 +4 -4
- data/History.md +140 -3
- data/README.md +28 -6
- data/docs/architecture.md +49 -16
- data/docs/compile_options.md +4 -2
- data/docs/deployment.md +53 -52
- data/docs/plugins.md +15 -15
- data/docs/rails_dev_mode.md +2 -3
- data/docs/restart.md +6 -6
- data/docs/signals.md +11 -10
- data/docs/stats.md +8 -8
- data/docs/systemd.md +63 -67
- data/ext/puma_http11/extconf.rb +18 -7
- data/ext/puma_http11/http11_parser.c +23 -10
- data/ext/puma_http11/http11_parser_common.rl +1 -1
- data/ext/puma_http11/mini_ssl.c +75 -12
- data/ext/puma_http11/org/jruby/puma/Http11Parser.java +49 -47
- data/ext/puma_http11/org/jruby/puma/MiniSSL.java +38 -55
- data/ext/puma_http11/puma_http11.c +1 -1
- data/lib/puma/app/status.rb +3 -0
- data/lib/puma/binder.rb +20 -6
- data/lib/puma/cli.rb +9 -4
- data/lib/puma/client.rb +68 -18
- data/lib/puma/cluster/worker.rb +7 -17
- data/lib/puma/cluster/worker_handle.rb +4 -0
- data/lib/puma/cluster.rb +29 -21
- data/lib/puma/configuration.rb +4 -1
- data/lib/puma/const.rb +7 -8
- data/lib/puma/control_cli.rb +19 -13
- data/lib/puma/detect.rb +8 -2
- data/lib/puma/dsl.rb +91 -10
- data/lib/puma/launcher.rb +13 -1
- data/lib/puma/minissl/context_builder.rb +8 -6
- data/lib/puma/minissl.rb +28 -7
- data/lib/puma/null_io.rb +5 -0
- data/lib/puma/plugin.rb +1 -1
- data/lib/puma/request.rb +15 -6
- data/lib/puma/runner.rb +22 -8
- data/lib/puma/server.rb +29 -30
- data/lib/puma/state_file.rb +42 -7
- data/lib/puma/thread_pool.rb +2 -2
- data/lib/puma/util.rb +19 -3
- data/lib/puma.rb +5 -3
- data/lib/rack/version_restriction.rb +15 -0
- data/tools/Dockerfile +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f1995d9f43f5297e945ba772d6fa72f814ef2878a6c819ab16774cfab9cf73e
|
4
|
+
data.tar.gz: f19f67fa86baadcfd6597212ccf50ca1c8dd7879d9920a7a7cf19839a0c4ede4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 335b387a7b47b246c3970cbd98556053627e2ef16b00d738a26ac8b67db8847f43b96ebfaddc695ea101a8c9aa9b8189e97b728aaf2596f74e4bbd32d30476f4
|
7
|
+
data.tar.gz: 02e6d936b3118718c2e9023b8ac512c82ddfed052ccdae9a64965a9d994589ff8f98cdcdad15e6b5c01bbc0bd0cc3ddf203afdb1c7be3ec9c81c26ee2e9479a2
|
data/History.md
CHANGED
@@ -1,3 +1,82 @@
|
|
1
|
+
## 5.6.7 / 2023-08-18
|
2
|
+
|
3
|
+
* Security
|
4
|
+
* 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
|
+
|
6
|
+
## 5.6.6 / 2023-06-21
|
7
|
+
|
8
|
+
* Bugfix
|
9
|
+
* Allow Puma to be loaded with Rack 3 ([#3166])
|
10
|
+
|
11
|
+
## 5.6.5 / 2022-08-23
|
12
|
+
|
13
|
+
* Feature
|
14
|
+
* Puma::ControlCLI - allow refork command to be sent as a request ([#2868], [#2866])
|
15
|
+
|
16
|
+
* Bugfixes
|
17
|
+
* NullIO#closed should return false ([#2883])
|
18
|
+
* [jruby] Fix TLS verification hang ([#2890], [#2729])
|
19
|
+
* extconf.rb - don't use pkg_config('openssl') if '--with-openssl-dir' is used ([#2885], [#2839])
|
20
|
+
* MiniSSL - detect SSL_CTX_set_dh_auto ([#2864], [#2863])
|
21
|
+
* Fix rack.after_reply exceptions breaking connections ([#2861], [#2856])
|
22
|
+
* Escape SSL cert and filenames ([#2855])
|
23
|
+
* Fail hard if SSL certs or keys are invalid ([#2848])
|
24
|
+
* Fail hard if SSL certs or keys cannot be read by user ([#2847])
|
25
|
+
* Fix build with Opaque DH in LibreSSL 3.5. ([#2838])
|
26
|
+
* Pre-existing socket file removed when TERM is issued after USR2 (if puma is running in cluster mode) ([#2817])
|
27
|
+
* Fix Puma::StateFile#load incompatibility ([#2810])
|
28
|
+
|
29
|
+
## 5.6.4 / 2022-03-30
|
30
|
+
|
31
|
+
* Security
|
32
|
+
* Close several HTTP Request Smuggling exploits (CVE-2022-24790)
|
33
|
+
|
34
|
+
## 5.6.2 / 2022-02-11
|
35
|
+
|
36
|
+
* Bugfix/Security
|
37
|
+
* Response body will always be `close`d. (GHSA-rmj8-8hhh-gv5h, related to [#2809])
|
38
|
+
|
39
|
+
## 5.6.1 / 2022-01-26
|
40
|
+
|
41
|
+
* Bugfixes
|
42
|
+
* Reverted a commit which appeared to be causing occasional blank header values ([#2809])
|
43
|
+
|
44
|
+
## 5.6.0 / 2022-01-25
|
45
|
+
|
46
|
+
* Features
|
47
|
+
* Support `localhost` integration in `ssl_bind` ([#2764], [#2708])
|
48
|
+
* Allow backlog parameter to be set with ssl_bind DSL ([#2780])
|
49
|
+
* Remove yaml (psych) requirement in StateFile ([#2784])
|
50
|
+
* Allow culling of oldest workers, previously was only youngest ([#2773], [#2794])
|
51
|
+
* Add worker_check_interval configuration option ([#2759])
|
52
|
+
* Always send lowlevel_error response to client ([#2731], [#2341])
|
53
|
+
* Support for cert_pem and key_pem with ssl_bind DSL ([#2728])
|
54
|
+
|
55
|
+
* Bugfixes
|
56
|
+
* Keep thread names under 15 characters, prevents breakage on some OSes ([#2733])
|
57
|
+
* Fix two 'old-style-definition' compile warning ([#2807], [#2806])
|
58
|
+
* Log environment correctly using option value ([#2799])
|
59
|
+
* Fix warning from Ruby master (will be 3.2.0) ([#2785])
|
60
|
+
* extconf.rb - fix openssl with old Windows builds ([#2757])
|
61
|
+
* server.rb - rescue handling (`Errno::EBADF`) for `@notify.close` ([#2745])
|
62
|
+
|
63
|
+
* Refactor
|
64
|
+
* server.rb - refactor code using @options[:remote_address] ([#2742])
|
65
|
+
* [jruby] a couple refactorings - avoid copy-ing bytes ([#2730])
|
66
|
+
|
67
|
+
## 5.5.2 / 2021-10-12
|
68
|
+
|
69
|
+
* Bugfixes
|
70
|
+
* Allow UTF-8 in HTTP header values
|
71
|
+
|
72
|
+
## 5.5.1 / 2021-10-12
|
73
|
+
|
74
|
+
* Feature (added as mistake - we don't normally do this on bugfix releases, sorry!)
|
75
|
+
* Allow setting APP_ENV in preference to RACK_ENV or RAILS_ENV ([#2702])
|
76
|
+
|
77
|
+
* Security
|
78
|
+
* Do not allow LF as a line ending in a header (CVE-2021-41136)
|
79
|
+
|
1
80
|
## 5.5.0 / 2021-09-19
|
2
81
|
|
3
82
|
* Features
|
@@ -251,6 +330,16 @@
|
|
251
330
|
* Support parallel tests in verbose progress reporting ([#2223])
|
252
331
|
* Refactor error handling in server accept loop ([#2239])
|
253
332
|
|
333
|
+
## 4.3.10 / 2021-10-12
|
334
|
+
|
335
|
+
* Bugfixes
|
336
|
+
* Allow UTF-8 in HTTP header values
|
337
|
+
|
338
|
+
## 4.3.9 / 2021-10-12
|
339
|
+
|
340
|
+
* Security
|
341
|
+
* Do not allow LF as a line ending in a header (CVE-2021-41136)
|
342
|
+
|
254
343
|
## 4.3.8 / 2021-05-11
|
255
344
|
|
256
345
|
* Security
|
@@ -1784,6 +1873,54 @@ be added back in a future date when a java Puma::MiniSSL is added.
|
|
1784
1873
|
* Bugfixes
|
1785
1874
|
* Your bugfix goes here <Most recent on the top, like GitHub> (#Github Number)
|
1786
1875
|
|
1876
|
+
[#3166]:https://github.com/puma/puma/issues/3166 "Issue by @JoeDupuis, merged 2023-06-08"
|
1877
|
+
[#2883]:https://github.com/puma/puma/pull/2883 "PR by @MSP-Greg, merged 2022-06-02"
|
1878
|
+
[#2868]:https://github.com/puma/puma/pull/2868 "PR by @MSP-Greg, merged 2022-06-02"
|
1879
|
+
[#2866]:https://github.com/puma/puma/issues/2866 "Issue by @slondr, closed 2022-06-02"
|
1880
|
+
[#2888]:https://github.com/puma/puma/pull/2888 "PR by @MSP-Greg, merged 2022-06-01"
|
1881
|
+
[#2890]:https://github.com/puma/puma/pull/2890 "PR by @kares, merged 2022-06-01"
|
1882
|
+
[#2729]:https://github.com/puma/puma/issues/2729 "Issue by @kares, closed 2022-06-01"
|
1883
|
+
[#2885]:https://github.com/puma/puma/pull/2885 "PR by @MSP-Greg, merged 2022-05-30"
|
1884
|
+
[#2839]:https://github.com/puma/puma/issues/2839 "Issue by @wlipa, closed 2022-05-30"
|
1885
|
+
[#2882]:https://github.com/puma/puma/pull/2882 "PR by @MSP-Greg, merged 2022-05-19"
|
1886
|
+
[#2864]:https://github.com/puma/puma/pull/2864 "PR by @MSP-Greg, merged 2022-04-26"
|
1887
|
+
[#2863]:https://github.com/puma/puma/issues/2863 "Issue by @eradman, closed 2022-04-26"
|
1888
|
+
[#2861]:https://github.com/puma/puma/pull/2861 "PR by @BlakeWilliams, merged 2022-04-17"
|
1889
|
+
[#2856]:https://github.com/puma/puma/issues/2856 "Issue by @nateberkopec, closed 2022-04-17"
|
1890
|
+
[#2855]:https://github.com/puma/puma/pull/2855 "PR by @stanhu, merged 2022-04-09"
|
1891
|
+
[#2848]:https://github.com/puma/puma/pull/2848 "PR by @stanhu, merged 2022-04-02"
|
1892
|
+
[#2847]:https://github.com/puma/puma/pull/2847 "PR by @stanhu, merged 2022-04-02"
|
1893
|
+
[#2838]:https://github.com/puma/puma/pull/2838 "PR by @epsilon-0, merged 2022-03-03"
|
1894
|
+
[#2817]:https://github.com/puma/puma/pull/2817 "PR by @khustochka, merged 2022-02-20"
|
1895
|
+
[#2810]:https://github.com/puma/puma/pull/2810 "PR by @kzkn, merged 2022-01-27"
|
1896
|
+
[#2899]:https://github.com/puma/puma/pull/2899 "PR by @kares, merged 2022-07-04"
|
1897
|
+
[#2891]:https://github.com/puma/puma/pull/2891 "PR by @gingerlime, merged 2022-06-02"
|
1898
|
+
[#2886]:https://github.com/puma/puma/pull/2886 "PR by @kares, merged 2022-05-30"
|
1899
|
+
[#2884]:https://github.com/puma/puma/pull/2884 "PR by @kares, merged 2022-05-30"
|
1900
|
+
[#2875]:https://github.com/puma/puma/pull/2875 "PR by @ylecuyer, merged 2022-05-19"
|
1901
|
+
[#2840]:https://github.com/puma/puma/pull/2840 "PR by @LukaszMaslej, merged 2022-04-13"
|
1902
|
+
[#2849]:https://github.com/puma/puma/pull/2849 "PR by @kares, merged 2022-04-09"
|
1903
|
+
[#2809]:https://github.com/puma/puma/pull/2809 "PR by @dentarg, merged 2022-01-26"
|
1904
|
+
[#2764]:https://github.com/puma/puma/pull/2764 "PR by @dentarg, merged 2022-01-18"
|
1905
|
+
[#2708]:https://github.com/puma/puma/issues/2708 "Issue by @erikaxel, closed 2022-01-18"
|
1906
|
+
[#2780]:https://github.com/puma/puma/pull/2780 "PR by @dalibor, merged 2022-01-01"
|
1907
|
+
[#2784]:https://github.com/puma/puma/pull/2784 "PR by @MSP-Greg, merged 2022-01-01"
|
1908
|
+
[#2773]:https://github.com/puma/puma/pull/2773 "PR by @ob-stripe, merged 2022-01-01"
|
1909
|
+
[#2794]:https://github.com/puma/puma/pull/2794 "PR by @johnnyshields, merged 2022-01-10"
|
1910
|
+
[#2759]:https://github.com/puma/puma/pull/2759 "PR by @ob-stripe, merged 2021-12-11"
|
1911
|
+
[#2731]:https://github.com/puma/puma/pull/2731 "PR by @baelter, merged 2021-11-02"
|
1912
|
+
[#2341]:https://github.com/puma/puma/issues/2341 "Issue by @cjlarose, closed 2021-11-02"
|
1913
|
+
[#2728]:https://github.com/puma/puma/pull/2728 "PR by @dalibor, merged 2021-10-31"
|
1914
|
+
[#2733]:https://github.com/puma/puma/pull/2733 "PR by @ob-stripe, merged 2021-12-12"
|
1915
|
+
[#2807]:https://github.com/puma/puma/pull/2807 "PR by @MSP-Greg, merged 2022-01-25"
|
1916
|
+
[#2806]:https://github.com/puma/puma/issues/2806 "Issue by @olleolleolle, closed 2022-01-25"
|
1917
|
+
[#2799]:https://github.com/puma/puma/pull/2799 "PR by @ags, merged 2022-01-22"
|
1918
|
+
[#2785]:https://github.com/puma/puma/pull/2785 "PR by @MSP-Greg, merged 2022-01-02"
|
1919
|
+
[#2757]:https://github.com/puma/puma/pull/2757 "PR by @MSP-Greg, merged 2021-11-24"
|
1920
|
+
[#2745]:https://github.com/puma/puma/pull/2745 "PR by @MSP-Greg, merged 2021-11-03"
|
1921
|
+
[#2742]:https://github.com/puma/puma/pull/2742 "PR by @MSP-Greg, merged 2021-12-12"
|
1922
|
+
[#2730]:https://github.com/puma/puma/pull/2730 "PR by @kares, merged 2021-11-01"
|
1923
|
+
[#2702]:https://github.com/puma/puma/pull/2702 "PR by @jacobherrington, merged 2021-09-21"
|
1787
1924
|
[#2610]:https://github.com/puma/puma/pull/2610 "PR by @ye-lin-aung, merged 2021-08-18"
|
1788
1925
|
[#2257]:https://github.com/puma/puma/issues/2257 "Issue by @nateberkopec, closed 2021-08-18"
|
1789
1926
|
[#2654]:https://github.com/puma/puma/pull/2654 "PR by @Roguelazer, merged 2021-09-07"
|
@@ -1848,7 +1985,7 @@ be added back in a future date when a java Puma::MiniSSL is added.
|
|
1848
1985
|
[#2519]:https://github.com/puma/puma/pull/2519 "PR by @MSP-Greg, merged 2021-01-26"
|
1849
1986
|
[#2522]:https://github.com/puma/puma/pull/2522 "PR by @jcmfernandes, merged 2021-01-12"
|
1850
1987
|
[#2490]:https://github.com/puma/puma/pull/2490 "PR by @Bonias, merged 2020-12-07"
|
1851
|
-
[#2486]:https://github.com/puma/puma/pull/2486 "PR by @
|
1988
|
+
[#2486]:https://github.com/puma/puma/pull/2486 "PR by @karloscodes, merged 2020-12-02"
|
1852
1989
|
[#2535]:https://github.com/puma/puma/pull/2535 "PR by @MSP-Greg, merged 2021-01-27"
|
1853
1990
|
[#2529]:https://github.com/puma/puma/pull/2529 "PR by @MSP-Greg, merged 2021-01-24"
|
1854
1991
|
[#2533]:https://github.com/puma/puma/pull/2533 "PR by @MSP-Greg, merged 2021-01-24"
|
@@ -1858,7 +1995,7 @@ be added back in a future date when a java Puma::MiniSSL is added.
|
|
1858
1995
|
[#2521]:https://github.com/puma/puma/pull/2521 "PR by @ojab, merged 2021-01-04"
|
1859
1996
|
[#2531]:https://github.com/puma/puma/pull/2531 "PR by @wjordan, merged 2021-01-19"
|
1860
1997
|
[#2510]:https://github.com/puma/puma/pull/2510 "PR by @micke, merged 2020-12-10"
|
1861
|
-
[#2472]:https://github.com/puma/puma/pull/2472 "PR by @
|
1998
|
+
[#2472]:https://github.com/puma/puma/pull/2472 "PR by @karloscodes, merged 2020-11-02"
|
1862
1999
|
[#2438]:https://github.com/puma/puma/pull/2438 "PR by @ekohl, merged 2020-10-26"
|
1863
2000
|
[#2406]:https://github.com/puma/puma/pull/2406 "PR by @fdel15, merged 2020-10-19"
|
1864
2001
|
[#2449]:https://github.com/puma/puma/pull/2449 "PR by @MSP-Greg, merged 2020-10-28"
|
@@ -2285,7 +2422,7 @@ be added back in a future date when a java Puma::MiniSSL is added.
|
|
2285
2422
|
[#709]:https://github.com/puma/puma/pull/709 "PR by @lian, merged 2015-06-10"
|
2286
2423
|
[#711]:https://github.com/puma/puma/pull/711 "PR by @julik, merged 2015-06-10"
|
2287
2424
|
[#712]:https://github.com/puma/puma/pull/712 "PR by @chewi, merged 2015-07-14"
|
2288
|
-
[#715]:https://github.com/puma/puma/pull/715 "PR by @
|
2425
|
+
[#715]:https://github.com/puma/puma/pull/715 "PR by @raymondmars, merged 2015-07-14"
|
2289
2426
|
[#725]:https://github.com/puma/puma/pull/725 "PR by @rwz, merged 2015-07-14"
|
2290
2427
|
[#726]:https://github.com/puma/puma/pull/726 "PR by @jshafton, merged 2015-07-14"
|
2291
2428
|
[#729]:https://github.com/puma/puma/pull/729 "PR by @allaire, merged 2015-07-14"
|
data/README.md
CHANGED
@@ -137,6 +137,11 @@ This code can be used to setup the process before booting the application, allow
|
|
137
137
|
you to do some Puma-specific things that you don't want to embed in your application.
|
138
138
|
For instance, you could fire a log notification that a worker booted or send something to statsd. This can be called multiple times.
|
139
139
|
|
140
|
+
Constants loaded by your application (such as `Rails`) will not be available in `on_worker_boot`.
|
141
|
+
However, these constants _will_ be available if `preload_app!` is enabled, either explicitly in your `puma` config or automatically if
|
142
|
+
using 2 or more workers in cluster mode.
|
143
|
+
If `preload_app!` is not enabled and 1 worker is used, then `on_worker_boot` will fire, but your app will not be preloaded and constants will not be available.
|
144
|
+
|
140
145
|
`before_fork` specifies a block to be run before workers are forked:
|
141
146
|
|
142
147
|
```ruby
|
@@ -187,21 +192,38 @@ Need a bit of security? Use SSL sockets:
|
|
187
192
|
```
|
188
193
|
$ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'
|
189
194
|
```
|
190
|
-
#### Self-signed SSL certificates (via
|
195
|
+
#### Self-signed SSL certificates (via the [`localhost`] gem, for development use):
|
196
|
+
|
197
|
+
Puma supports the [`localhost`] gem for self-signed certificates. This is particularly useful if you want to use Puma with SSL locally, and self-signed certificates will work for your use-case. Currently, the integration can only be used in MRI.
|
191
198
|
|
192
|
-
Puma
|
199
|
+
Puma automatically configures SSL when the [`localhost`] gem is loaded in a `development` environment:
|
193
200
|
|
194
201
|
```ruby
|
195
|
-
#
|
202
|
+
# Add the gem to your Gemfile
|
203
|
+
group(:development) do
|
204
|
+
gem 'localhost'
|
205
|
+
end
|
206
|
+
|
207
|
+
# And require it implicitly using bundler
|
208
|
+
require "bundler"
|
209
|
+
Bundler.require(:default, ENV["RACK_ENV"].to_sym)
|
210
|
+
|
211
|
+
# Alternatively, you can require the gem in config.ru:
|
196
212
|
require './app'
|
197
|
-
require 'localhost
|
213
|
+
require 'localhost'
|
198
214
|
run Sinatra::Application
|
215
|
+
```
|
199
216
|
|
200
|
-
|
217
|
+
Additionally, Puma must be listening to an SSL socket:
|
201
218
|
|
219
|
+
```shell
|
202
220
|
$ puma -b 'ssl://localhost:9292' config.ru
|
221
|
+
|
222
|
+
# The following options allow you to reach Puma over HTTP as well:
|
223
|
+
$ puma -b ssl://localhost:9292 -b tcp://localhost:9393 config.ru
|
203
224
|
```
|
204
225
|
|
226
|
+
[`localhost`]: https://github.com/socketry/localhost
|
205
227
|
|
206
228
|
#### Controlling SSL Cipher Suites
|
207
229
|
|
@@ -270,7 +292,7 @@ You can also provide a configuration file with the `-C` (or `--config`) flag:
|
|
270
292
|
$ puma -C /path/to/config
|
271
293
|
```
|
272
294
|
|
273
|
-
If no configuration file is specified, Puma will look for a configuration file at `config/puma.rb`. If an environment is specified
|
295
|
+
If no configuration file is specified, Puma will look for a configuration file at `config/puma.rb`. If an environment is specified (via the `--environment` flag or through the `APP_ENV`, `RACK_ENV`, or `RAILS_ENV` environment variables) Puma looks for a configuration file at `config/puma/<environment_name>.rb` and then falls back to `config/puma.rb`.
|
274
296
|
|
275
297
|
If you want to prevent Puma from looking for a configuration file in those locations, include the `--no-config` flag:
|
276
298
|
|
data/docs/architecture.md
CHANGED
@@ -4,38 +4,71 @@
|
|
4
4
|
|
5
5
|
![https://bit.ly/2iJuFky](images/puma-general-arch.png)
|
6
6
|
|
7
|
-
Puma is a threaded Ruby HTTP application server
|
7
|
+
Puma is a threaded Ruby HTTP application server processing requests across a TCP
|
8
|
+
and/or UNIX socket.
|
8
9
|
|
9
10
|
|
10
|
-
Puma processes (there can be one or many) accept connections from the socket via
|
11
|
+
Puma processes (there can be one or many) accept connections from the socket via
|
12
|
+
a thread (in the [`Reactor`](../lib/puma/reactor.rb) class). The connection,
|
13
|
+
once fully buffered and read, moves into the `todo` list, where an available
|
14
|
+
thread will pick it up (in the [`ThreadPool`](../lib/puma/thread_pool.rb)
|
15
|
+
class).
|
11
16
|
|
12
|
-
Puma works in two main modes: cluster and single. In single mode, only one Puma
|
17
|
+
Puma works in two main modes: cluster and single. In single mode, only one Puma
|
18
|
+
process boots. In cluster mode, a `master` process is booted, which prepares
|
19
|
+
(and may boot) the application and then uses the `fork()` system call to create
|
20
|
+
one or more `child` processes. These `child` processes all listen to the same
|
21
|
+
socket. The `master` process does not listen to the socket or process requests -
|
22
|
+
its purpose is primarily to manage and listen for UNIX signals and possibly kill
|
23
|
+
or boot `child` processes.
|
13
24
|
|
14
|
-
We sometimes call `child` processes (or Puma processes in `single` mode)
|
25
|
+
We sometimes call `child` processes (or Puma processes in `single` mode)
|
26
|
+
_workers_, and we sometimes call the threads created by Puma's
|
27
|
+
[`ThreadPool`](../lib/puma/thread_pool.rb) _worker threads_.
|
15
28
|
|
16
29
|
## How Requests Work
|
17
30
|
|
18
31
|
![https://bit.ly/2zwzhEK](images/puma-connection-flow.png)
|
19
32
|
|
20
33
|
* Upon startup, Puma listens on a TCP or UNIX socket.
|
21
|
-
* The backlog of this socket is configured
|
22
|
-
|
23
|
-
|
24
|
-
|
34
|
+
* The backlog of this socket is configured with a default of 1024, but the
|
35
|
+
actual backlog value is capped by the `net.core.somaxconn` sysctl value.
|
36
|
+
The backlog determines the size of the queue for unaccepted connections. If
|
37
|
+
the backlog is full, the operating system is not accepting new connections.
|
38
|
+
* This socket backlog is distinct from the `backlog` of work as reported by
|
39
|
+
`Puma.stats` or the control server. The backlog that `Puma.stats` refers to
|
40
|
+
represents the number of connections in the process' `todo` set waiting for
|
41
|
+
a thread from the [`ThreadPool`](../lib/puma/thread_pool.rb).
|
42
|
+
* By default, a single, separate thread (created by the
|
43
|
+
[`Reactor`](../lib/puma/reactor.rb) class) reads and buffers requests from the
|
44
|
+
socket.
|
45
|
+
* When at least one worker thread is available for work, the reactor thread
|
46
|
+
listens to the socket and accepts a request (if one is waiting).
|
25
47
|
* The reactor thread waits for the entire HTTP request to be received.
|
26
|
-
*
|
27
|
-
|
48
|
+
* Puma exposes the time spent waiting for the HTTP request body to be
|
49
|
+
received to the Rack app as `env['puma.request_body_wait']`
|
50
|
+
(milliseconds).
|
51
|
+
* Once fully buffered and received, the connection is pushed into the "todo"
|
52
|
+
set.
|
28
53
|
* Worker threads pop work off the "todo" set for processing.
|
29
|
-
* The worker thread processes the request via `call`ing the configured Rack
|
30
|
-
|
31
|
-
*
|
54
|
+
* The worker thread processes the request via `call`ing the configured Rack
|
55
|
+
application. The Rack application generates the HTTP response.
|
56
|
+
* The worker thread writes the response to the connection. While Puma buffers
|
57
|
+
requests via a separate thread, it does not use a separate thread for
|
58
|
+
responses.
|
59
|
+
* Once done, the thread becomes available to process another connection in the
|
60
|
+
"todo" set.
|
32
61
|
|
33
62
|
### `queue_requests`
|
34
63
|
|
35
64
|
![https://bit.ly/2zxCJ1Z](images/puma-connection-flow-no-reactor.png)
|
36
65
|
|
37
|
-
The `queue_requests` option is `true` by default, enabling the separate reactor
|
66
|
+
The `queue_requests` option is `true` by default, enabling the separate reactor
|
67
|
+
thread used to buffer requests as described above.
|
38
68
|
|
39
|
-
If set to `false`, this buffer will not be used for connections while waiting
|
69
|
+
If set to `false`, this buffer will not be used for connections while waiting
|
70
|
+
for the request to arrive.
|
40
71
|
|
41
|
-
In this mode, when a connection is accepted, it is added to the "todo" queue
|
72
|
+
In this mode, when a connection is accepted, it is added to the "todo" queue
|
73
|
+
immediately, and a worker will synchronously do any waiting necessary to read
|
74
|
+
the HTTP request from the socket.
|
data/docs/compile_options.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
# Compile Options
|
2
2
|
|
3
|
-
There are some `cflags` provided to change Puma's default configuration for its
|
3
|
+
There are some `cflags` provided to change Puma's default configuration for its
|
4
|
+
C extension.
|
4
5
|
|
5
6
|
## Query String, `PUMA_QUERY_STRING_MAX_LENGTH`
|
6
7
|
|
7
|
-
By default, the max length of `QUERY_STRING` is `1024 * 10`. But you may want to
|
8
|
+
By default, the max length of `QUERY_STRING` is `1024 * 10`. But you may want to
|
9
|
+
adjust it to accept longer queries in GET requests.
|
8
10
|
|
9
11
|
For manual install, pass the `PUMA_QUERY_STRING_MAX_LENGTH` option like this:
|
10
12
|
|
data/docs/deployment.md
CHANGED
@@ -1,35 +1,32 @@
|
|
1
1
|
# Deployment engineering for Puma
|
2
2
|
|
3
|
-
Puma
|
4
|
-
|
5
|
-
it in their production deployments as well.
|
3
|
+
Puma expects to be run in a deployed environment eventually. You can use it as
|
4
|
+
your development server, but most people use it in their production deployments.
|
6
5
|
|
7
|
-
To that end, this
|
8
|
-
|
6
|
+
To that end, this document serves as a foundation of wisdom regarding deploying
|
7
|
+
Puma to production while increasing happiness and decreasing downtime.
|
9
8
|
|
10
9
|
## Specifying Puma
|
11
10
|
|
12
|
-
Most people
|
13
|
-
|
11
|
+
Most people will specify Puma by including `gem "puma"` in a Gemfile, so we'll
|
12
|
+
assume this is how you're using Puma.
|
14
13
|
|
15
|
-
|
14
|
+
## Single vs. Cluster mode
|
16
15
|
|
17
|
-
|
16
|
+
Initially, Puma was conceived as a thread-only web server, but support for
|
17
|
+
processes was added in version 2.
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
To run `puma` in single mode (i.e., as a development environment), set the
|
20
|
+
number of workers to 0; anything higher will run in cluster mode.
|
21
21
|
|
22
|
-
|
23
|
-
set the number of workers to 0, anything above will run in cluster mode.
|
24
|
-
|
25
|
-
Here are some rules of thumb for cluster mode:
|
22
|
+
Here are some tips for cluster mode:
|
26
23
|
|
27
24
|
### MRI
|
28
25
|
|
29
|
-
* Use cluster mode and set the number of workers to 1.5x the number of
|
30
|
-
in the machine, minimum 2.
|
31
|
-
* Set the number of threads to desired concurrent requests
|
32
|
-
Puma defaults to 5 and that's a decent number.
|
26
|
+
* Use cluster mode and set the number of workers to 1.5x the number of CPU cores
|
27
|
+
in the machine, starting from a minimum of 2.
|
28
|
+
* Set the number of threads to desired concurrent requests/number of workers.
|
29
|
+
Puma defaults to 5, and that's a decent number.
|
33
30
|
|
34
31
|
#### Migrating from Unicorn
|
35
32
|
|
@@ -37,7 +34,7 @@ Here are some rules of thumb for cluster mode:
|
|
37
34
|
* Set workers to half the number of unicorn workers you're using
|
38
35
|
* Set threads to 2
|
39
36
|
* Enjoy 50% memory savings
|
40
|
-
* As you grow more confident in the thread
|
37
|
+
* As you grow more confident in the thread-safety of your app, you can tune the
|
41
38
|
workers down and the threads up.
|
42
39
|
|
43
40
|
#### Ubuntu / Systemd (Systemctl) Installation
|
@@ -48,54 +45,58 @@ See [systemd.md](systemd.md)
|
|
48
45
|
|
49
46
|
**How do you know if you've got enough (or too many workers)?**
|
50
47
|
|
51
|
-
A good question. Due to MRI's GIL, only one thread can be executing Ruby code at
|
52
|
-
But since so many apps are waiting on IO from DBs, etc., they can
|
53
|
-
|
48
|
+
A good question. Due to MRI's GIL, only one thread can be executing Ruby code at
|
49
|
+
a time. But since so many apps are waiting on IO from DBs, etc., they can
|
50
|
+
utilize threads to use the process more efficiently.
|
54
51
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
52
|
+
Generally, you never want processes that are pegged all the time. That can mean
|
53
|
+
there is more work to do than the process can get through. On the other hand, if
|
54
|
+
you have processes that sit around doing nothing, then they're just eating up
|
55
|
+
resources.
|
59
56
|
|
60
|
-
Watch your CPU utilization over time and aim for about 70% on average.
|
61
|
-
you've got capacity still but aren't starving threads.
|
57
|
+
Watch your CPU utilization over time and aim for about 70% on average. 70%
|
58
|
+
utilization means you've got capacity still but aren't starving threads.
|
62
59
|
|
63
60
|
**Measuring utilization**
|
64
61
|
|
65
|
-
Using a timestamp header from an upstream proxy server (
|
66
|
-
|
67
|
-
thread to become available.
|
62
|
+
Using a timestamp header from an upstream proxy server (e.g., `nginx` or
|
63
|
+
`haproxy`) makes it possible to indicate how long requests have been waiting for
|
64
|
+
a Puma thread to become available.
|
68
65
|
|
69
66
|
* Have your upstream proxy set a header with the time it received the request:
|
70
67
|
* nginx: `proxy_set_header X-Request-Start "${msec}";`
|
71
|
-
* haproxy >= 1.9: `http-request set-header X-Request-Start
|
68
|
+
* haproxy >= 1.9: `http-request set-header X-Request-Start
|
69
|
+
t=%[date()]%[date_us()]`
|
72
70
|
* haproxy < 1.9: `http-request set-header X-Request-Start t=%[date()]`
|
73
|
-
* In your Rack middleware, determine the amount of time elapsed since
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
*
|
78
|
-
|
71
|
+
* In your Rack middleware, determine the amount of time elapsed since
|
72
|
+
`X-Request-Start`.
|
73
|
+
* To improve accuracy, you will want to subtract time spent waiting for slow
|
74
|
+
clients:
|
75
|
+
* `env['puma.request_body_wait']` contains the number of milliseconds Puma
|
76
|
+
spent waiting for the client to send the request body.
|
77
|
+
* haproxy: `%Th` (TLS handshake time) and `%Ti` (idle time before request)
|
78
|
+
can can also be added as headers.
|
79
79
|
|
80
80
|
## Should I daemonize?
|
81
81
|
|
82
|
-
|
82
|
+
The Puma 5.0 release removed daemonization. For older versions and alternatives,
|
83
|
+
continue reading.
|
83
84
|
|
84
|
-
I prefer to
|
85
|
-
monitor them as child processes. This gives them fast response to crashes and
|
85
|
+
I prefer not to daemonize my servers and use something like `runit` or `systemd`
|
86
|
+
to monitor them as child processes. This gives them fast response to crashes and
|
86
87
|
makes it easy to figure out what is going on. Additionally, unlike `unicorn`,
|
87
|
-
|
88
|
+
Puma does not require daemonization to do zero-downtime restarts.
|
88
89
|
|
89
|
-
I see people using daemonization because they start puma directly via
|
90
|
-
task and thus want it to live on past the `cap deploy`. To these people I say:
|
91
|
-
You need to be using a process monitor. Nothing is making sure
|
92
|
-
this scenario! You're just waiting for something weird to happen,
|
93
|
-
and to get paged at
|
94
|
-
your OS comes with, be it `sysvinit` or `systemd`. Or branch out
|
95
|
-
|
90
|
+
I see people using daemonization because they start puma directly via Capistrano
|
91
|
+
task and thus want it to live on past the `cap deploy`. To these people, I say:
|
92
|
+
You need to be using a process monitor. Nothing is making sure Puma stays up in
|
93
|
+
this scenario! You're just waiting for something weird to happen, Puma to die,
|
94
|
+
and to get paged at 3 AM. Do yourself a favor, at least the process monitoring
|
95
|
+
your OS comes with, be it `sysvinit` or `systemd`. Or branch out and use `runit`
|
96
|
+
or hell, even `monit`.
|
96
97
|
|
97
98
|
## Restarting
|
98
99
|
|
99
100
|
You probably will want to deploy some new code at some point, and you'd like
|
100
|
-
|
101
|
-
|
101
|
+
Puma to start running that new code. There are a few options for restarting
|
102
|
+
Puma, described separately in our [restart documentation](restart.md).
|
data/docs/plugins.md
CHANGED
@@ -3,22 +3,22 @@
|
|
3
3
|
Puma 3.0 added support for plugins that can augment configuration and service
|
4
4
|
operations.
|
5
5
|
|
6
|
-
|
6
|
+
There are two canonical plugins to aid in the development of new plugins:
|
7
7
|
|
8
8
|
* [tmp\_restart](https://github.com/puma/puma/blob/master/lib/puma/plugin/tmp_restart.rb):
|
9
9
|
Restarts the server if the file `tmp/restart.txt` is touched
|
10
10
|
* [heroku](https://github.com/puma/puma-heroku/blob/master/lib/puma/plugin/heroku.rb):
|
11
|
-
Packages up the default configuration used by
|
11
|
+
Packages up the default configuration used by Puma on Heroku (being sunset
|
12
|
+
with the release of Puma 5.0)
|
12
13
|
|
13
|
-
Plugins are activated in a
|
14
|
+
Plugins are activated in a Puma configuration file (such as `config/puma.rb'`)
|
14
15
|
by adding `plugin "name"`, such as `plugin "heroku"`.
|
15
16
|
|
16
|
-
Plugins are activated based
|
17
|
-
|
18
|
-
|
19
|
-
puma plugins).
|
17
|
+
Plugins are activated based on path requirements so, activating the `heroku`
|
18
|
+
plugin is much like `require "puma/plugin/heroku"`. This allows gems to provide
|
19
|
+
multiple plugins (as well as unrelated gems to provide Puma plugins).
|
20
20
|
|
21
|
-
The `tmp_restart` plugin
|
21
|
+
The `tmp_restart` plugin comes with Puma, so it is always available.
|
22
22
|
|
23
23
|
To use the `heroku` plugin, add `puma-heroku` to your Gemfile or install it.
|
24
24
|
|
@@ -26,13 +26,13 @@ To use the `heroku` plugin, add `puma-heroku` to your Gemfile or install it.
|
|
26
26
|
|
27
27
|
## Server-wide hooks
|
28
28
|
|
29
|
-
Plugins can use a couple of hooks at server level: `start` and `config`.
|
29
|
+
Plugins can use a couple of hooks at the server level: `start` and `config`.
|
30
30
|
|
31
|
-
`start` runs when the server has started and allows the plugin to
|
32
|
-
functionality to augment
|
31
|
+
`start` runs when the server has started and allows the plugin to initiate other
|
32
|
+
functionality to augment Puma.
|
33
33
|
|
34
|
-
`config` runs when the server is being configured and
|
35
|
-
object that
|
34
|
+
`config` runs when the server is being configured and receives a `Puma::DSL`
|
35
|
+
object that is useful for additional configuration.
|
36
36
|
|
37
|
-
|
38
|
-
|
37
|
+
Public methods in [`Puma::Plugin`](../lib/puma/plugin.rb) are treated as a
|
38
|
+
public API for plugins.
|
data/docs/rails_dev_mode.md
CHANGED
@@ -2,16 +2,15 @@
|
|
2
2
|
|
3
3
|
## "Loopback requests"
|
4
4
|
|
5
|
-
Be cautious of "loopback requests"
|
5
|
+
Be cautious of "loopback requests," where a Rails application executes a request to a server that, in turn, results in another request back to the same Rails application before the first request completes. Having a loopback request will trigger [Rails' load interlock](https://guides.rubyonrails.org/threading_and_code_execution.html#load-interlock) mechanism. The load interlock mechanism prevents a thread from using Rails autoloading mechanism to load constants while the application code is still running inside another thread.
|
6
6
|
|
7
7
|
This issue only occurs in the development environment as Rails' load interlock is not used in production environments. Although we're not sure, we believe this issue may not occur with the new `zeitwerk` code loader.
|
8
8
|
|
9
9
|
### Solutions
|
10
10
|
|
11
|
-
|
12
11
|
#### 1. Bypass Rails' load interlock with `.permit_concurrent_loads`
|
13
12
|
|
14
|
-
Wrap the first request inside a block that will allow concurrent loads
|
13
|
+
Wrap the first request inside a block that will allow concurrent loads: [`ActiveSupport::Dependencies.interlock.permit_concurrent_loads`](https://guides.rubyonrails.org/threading_and_code_execution.html#permit-concurrent-loads). Anything wrapped inside the `.permit_concurrent_loads` block will bypass the load interlock mechanism, allowing new threads to access the Rails environment and boot properly.
|
15
14
|
|
16
15
|
###### Example
|
17
16
|
|