puma 5.3.1 → 5.6.4

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.

Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +152 -5
  3. data/LICENSE +0 -0
  4. data/README.md +47 -6
  5. data/bin/puma-wild +0 -0
  6. data/docs/architecture.md +49 -16
  7. data/docs/compile_options.md +4 -2
  8. data/docs/deployment.md +53 -67
  9. data/docs/fork_worker.md +0 -0
  10. data/docs/images/puma-connection-flow-no-reactor.png +0 -0
  11. data/docs/images/puma-connection-flow.png +0 -0
  12. data/docs/images/puma-general-arch.png +0 -0
  13. data/docs/jungle/README.md +0 -0
  14. data/docs/jungle/rc.d/README.md +0 -0
  15. data/docs/jungle/rc.d/puma.conf +0 -0
  16. data/docs/kubernetes.md +0 -0
  17. data/docs/nginx.md +0 -0
  18. data/docs/plugins.md +15 -15
  19. data/docs/rails_dev_mode.md +2 -3
  20. data/docs/restart.md +6 -6
  21. data/docs/signals.md +11 -10
  22. data/docs/stats.md +8 -8
  23. data/docs/systemd.md +64 -67
  24. data/ext/puma_http11/PumaHttp11Service.java +0 -0
  25. data/ext/puma_http11/ext_help.h +0 -0
  26. data/ext/puma_http11/extconf.rb +28 -5
  27. data/ext/puma_http11/http11_parser.c +23 -10
  28. data/ext/puma_http11/http11_parser.h +0 -0
  29. data/ext/puma_http11/http11_parser.java.rl +0 -0
  30. data/ext/puma_http11/http11_parser.rl +0 -0
  31. data/ext/puma_http11/http11_parser_common.rl +1 -1
  32. data/ext/puma_http11/mini_ssl.c +69 -9
  33. data/ext/puma_http11/no_ssl/PumaHttp11Service.java +0 -0
  34. data/ext/puma_http11/org/jruby/puma/Http11.java +0 -0
  35. data/ext/puma_http11/org/jruby/puma/Http11Parser.java +49 -47
  36. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +28 -43
  37. data/ext/puma_http11/puma_http11.c +1 -1
  38. data/lib/puma/app/status.rb +4 -4
  39. data/lib/puma/binder.rb +51 -6
  40. data/lib/puma/cli.rb +14 -4
  41. data/lib/puma/client.rb +106 -21
  42. data/lib/puma/cluster/worker.rb +14 -17
  43. data/lib/puma/cluster/worker_handle.rb +4 -0
  44. data/lib/puma/cluster.rb +30 -24
  45. data/lib/puma/commonlogger.rb +0 -0
  46. data/lib/puma/configuration.rb +6 -1
  47. data/lib/puma/const.rb +9 -8
  48. data/lib/puma/control_cli.rb +1 -1
  49. data/lib/puma/detect.rb +8 -2
  50. data/lib/puma/dsl.rb +106 -12
  51. data/lib/puma/error_logger.rb +0 -0
  52. data/lib/puma/events.rb +0 -0
  53. data/lib/puma/io_buffer.rb +0 -0
  54. data/lib/puma/jruby_restart.rb +0 -0
  55. data/lib/puma/{json.rb → json_serialization.rb} +1 -1
  56. data/lib/puma/launcher.rb +4 -1
  57. data/lib/puma/minissl/context_builder.rb +8 -6
  58. data/lib/puma/minissl.rb +24 -23
  59. data/lib/puma/null_io.rb +0 -0
  60. data/lib/puma/plugin/tmp_restart.rb +0 -0
  61. data/lib/puma/plugin.rb +2 -2
  62. data/lib/puma/queue_close.rb +0 -0
  63. data/lib/puma/rack/builder.rb +1 -1
  64. data/lib/puma/rack/urlmap.rb +0 -0
  65. data/lib/puma/rack_default.rb +0 -0
  66. data/lib/puma/reactor.rb +0 -0
  67. data/lib/puma/request.rb +27 -11
  68. data/lib/puma/runner.rb +22 -8
  69. data/lib/puma/server.rb +45 -44
  70. data/lib/puma/single.rb +0 -0
  71. data/lib/puma/state_file.rb +41 -7
  72. data/lib/puma/systemd.rb +0 -0
  73. data/lib/puma/thread_pool.rb +7 -5
  74. data/lib/puma/util.rb +8 -1
  75. data/lib/puma.rb +2 -2
  76. data/lib/rack/handler/puma.rb +0 -0
  77. data/tools/Dockerfile +1 -1
  78. data/tools/trickletest.rb +0 -0
  79. metadata +7 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bcabc9a852bfbed380445b6649ee9e27a2e4741994a27b579e5c4fe94ab6e282
4
- data.tar.gz: 00ae9ffe82807c9419afaaf955af384f2c87b07914ab36e32c060a83df4075e9
3
+ metadata.gz: ff9f4c8b81e1bfced36da8ecfe60912bd6bb37a2f989f2f8489d31cbe1a5947a
4
+ data.tar.gz: 6821bc93adc639fea1ed82559b0e67c70bfd86fa0b0ec641eed65e020fb53440
5
5
  SHA512:
6
- metadata.gz: 6a6d4ca8d9ffeea284756f5cc6418b0d6649e360ab5b76bec8db8a6bd6d5cf059957725f3ac50949fd15bc1e54f31c6f50b1b5073cef6814dfca042d84cc04e6
7
- data.tar.gz: f5ad303fd4d4d3256fa0b20a0d608c2cfdea87901c8c56407420078cac5cd69591a686d12153865855532d0702122d34c80bf60ae4aed1f5ec081d20d3414f7e
6
+ metadata.gz: 7b3eafbc651e03214851f79a89cb92637f7966f7d645446e15ac29e118d3b564aa28222ef54c1ea02f946da813172cf24bf9fb3b4c9d9b14dc1dadbc20754579
7
+ data.tar.gz: 760c958a8c56ee5ec7b2208e5d1d9e0ef31c09975d058cd535f42382895f76f0854a18c68f671b37736e1588a372bc752a676cbbd1a896a08bd97962642dc0b7
data/History.md CHANGED
@@ -1,7 +1,96 @@
1
+ ## 5.6.4 / 2022-03-30
2
+
3
+ * Security
4
+ * Close several HTTP Request Smuggling exploits (CVE-2022-24790)
5
+
6
+ ## 5.6.2 / 2022-02-11
7
+
8
+ * Bugfix/Security
9
+ * Response body will always be `close`d. (GHSA-rmj8-8hhh-gv5h, related to [#2809])
10
+
11
+ ## 5.6.1 / 2022-01-26
12
+
13
+ * Bugfixes
14
+ * Reverted a commit which appeared to be causing occasional blank header values ([#2809])
15
+
16
+ ## 5.6.0 / 2022-01-25
17
+
18
+ * Features
19
+ * Support `localhost` integration in `ssl_bind` ([#2764], [#2708])
20
+ * Allow backlog parameter to be set with ssl_bind DSL ([#2780])
21
+ * Remove yaml (psych) requirement in StateFile ([#2784])
22
+ * Allow culling of oldest workers, previously was only youngest ([#2773], [#2794])
23
+ * Add worker_check_interval configuration option ([#2759])
24
+ * Always send lowlevel_error response to client ([#2731], [#2341])
25
+ * Support for cert_pem and key_pem with ssl_bind DSL ([#2728])
26
+
27
+ * Bugfixes
28
+ * Keep thread names under 15 characters, prevents breakage on some OSes ([#2733])
29
+ * Fix two 'old-style-definition' compile warning ([#2807], [#2806])
30
+ * Log environment correctly using option value ([#2799])
31
+ * Fix warning from Ruby master (will be 3.2.0) ([#2785])
32
+ * extconf.rb - fix openssl with old Windows builds ([#2757])
33
+ * server.rb - rescue handling (`Errno::EBADF`) for `@notify.close` ([#2745])
34
+
35
+ * Refactor
36
+ * server.rb - refactor code using @options[:remote_address] ([#2742])
37
+ * [jruby] a couple refactorings - avoid copy-ing bytes ([#2730])
38
+
39
+ ## 5.5.2 / 2021-10-12
40
+
41
+ * Bugfixes
42
+ * Allow UTF-8 in HTTP header values
43
+
44
+ ## 5.5.1 / 2021-10-12
45
+
46
+ * Feature (added as mistake - we don't normally do this on bugfix releases, sorry!)
47
+ * Allow setting APP_ENV in preference to RACK_ENV or RAILS_ENV ([#2702])
48
+
49
+ * Security
50
+ * Do not allow LF as a line ending in a header (CVE-2021-41136)
51
+
52
+ ## 5.5.0 / 2021-09-19
53
+
54
+ * Features
55
+ * Automatic SSL certificate provisioning for localhost, via localhost gem ([#2610], [#2257])
56
+ * add support for the PROXY protocol (v1 only) ([#2654], [#2651])
57
+ * Add a semantic CLI option for no config file ([#2689])
58
+
59
+ * Bugfixes
60
+ * More elaborate exception handling - lets some dead pumas die. ([#2700], [#2699])
61
+ * allow multiple after_worker_fork hooks ([#2690])
62
+ * Preserve BUNDLE_APP_CONFIG on worker fork ([#2688], [#2687])
63
+
64
+ * Performance
65
+ * Fix performance of server-side SSL connection close. ([#2675])
66
+
67
+ ## 5.4.0 / 2021-07-28
68
+
69
+ * Features
70
+ * Better/expanded names for threadpool threads ([#2657])
71
+ * Allow pkg_config for OpenSSL ([#2648], [#1412])
72
+ * Add `rack_url_scheme` to Puma::DSL, allows setting of `rack.url_scheme` header ([#2586], [#2569])
73
+
74
+ * Bugfixes
75
+ * `Binder#parse` - allow for symlinked unix path, add create_activated_fds debug ENV ([#2643], [#2638])
76
+ * Fix deprecation warning: minissl.c - Use Random.bytes if available ([#2642])
77
+ * Client certificates: set session id context while creating SSLContext ([#2633])
78
+ * Fix deadlock issue in thread pool ([#2656])
79
+
80
+ * Refactor
81
+ * Replace `IO.select` with `IO#wait_*` when checking a single IO ([#2666])
82
+
83
+ ## 5.3.2 / 2021-05-21
84
+
85
+ * Bugfixes
86
+ * Gracefully handle Rack not accepting CLI options ([#2630], [#2626])
87
+ * Fix sigterm misbehavior ([#2629])
88
+ * Improvements to keepalive-connection shedding ([#2628])
89
+
1
90
  ## 5.3.1 / 2021-05-11
2
91
 
3
92
  * Security
4
- * Close keepalive connections after the maximum number of fast inlined requests (#2625)
93
+ * Close keepalive connections after the maximum number of fast inlined requests (CVE-2021-29509) ([#2625])
5
94
 
6
95
  ## 5.3.0 / 2021-05-07
7
96
 
@@ -213,10 +302,20 @@
213
302
  * Support parallel tests in verbose progress reporting ([#2223])
214
303
  * Refactor error handling in server accept loop ([#2239])
215
304
 
305
+ ## 4.3.10 / 2021-10-12
306
+
307
+ * Bugfixes
308
+ * Allow UTF-8 in HTTP header values
309
+
310
+ ## 4.3.9 / 2021-10-12
311
+
312
+ * Security
313
+ * Do not allow LF as a line ending in a header (CVE-2021-41136)
314
+
216
315
  ## 4.3.8 / 2021-05-11
217
316
 
218
317
  * Security
219
- * Close keepalive connections after the maximum number of fast inlined requests (#2625)
318
+ * Close keepalive connections after the maximum number of fast inlined requests (CVE-2021-29509) ([#2625])
220
319
 
221
320
  ## 4.3.7 / 2020-11-30
222
321
 
@@ -1746,6 +1845,54 @@ be added back in a future date when a java Puma::MiniSSL is added.
1746
1845
  * Bugfixes
1747
1846
  * Your bugfix goes here <Most recent on the top, like GitHub> (#Github Number)
1748
1847
 
1848
+ [#2809]:https://github.com/puma/puma/pull/2809 "PR by @dentarg, merged 2022-01-26"
1849
+ [#2764]:https://github.com/puma/puma/pull/2764 "PR by @dentarg, merged 2022-01-18"
1850
+ [#2708]:https://github.com/puma/puma/issues/2708 "Issue by @erikaxel, closed 2022-01-18"
1851
+ [#2780]:https://github.com/puma/puma/pull/2780 "PR by @dalibor, merged 2022-01-01"
1852
+ [#2784]:https://github.com/puma/puma/pull/2784 "PR by @MSP-Greg, merged 2022-01-01"
1853
+ [#2773]:https://github.com/puma/puma/pull/2773 "PR by @ob-stripe, merged 2022-01-01"
1854
+ [#2794]:https://github.com/puma/puma/pull/2794 "PR by @johnnyshields, merged 2022-01-10"
1855
+ [#2759]:https://github.com/puma/puma/pull/2759 "PR by @ob-stripe, merged 2021-12-11"
1856
+ [#2731]:https://github.com/puma/puma/pull/2731 "PR by @baelter, merged 2021-11-02"
1857
+ [#2341]:https://github.com/puma/puma/issues/2341 "Issue by @cjlarose, closed 2021-11-02"
1858
+ [#2728]:https://github.com/puma/puma/pull/2728 "PR by @dalibor, merged 2021-10-31"
1859
+ [#2733]:https://github.com/puma/puma/pull/2733 "PR by @ob-stripe, merged 2021-12-12"
1860
+ [#2807]:https://github.com/puma/puma/pull/2807 "PR by @MSP-Greg, merged 2022-01-25"
1861
+ [#2806]:https://github.com/puma/puma/issues/2806 "Issue by @olleolleolle, closed 2022-01-25"
1862
+ [#2799]:https://github.com/puma/puma/pull/2799 "PR by @ags, merged 2022-01-22"
1863
+ [#2785]:https://github.com/puma/puma/pull/2785 "PR by @MSP-Greg, merged 2022-01-02"
1864
+ [#2757]:https://github.com/puma/puma/pull/2757 "PR by @MSP-Greg, merged 2021-11-24"
1865
+ [#2745]:https://github.com/puma/puma/pull/2745 "PR by @MSP-Greg, merged 2021-11-03"
1866
+ [#2742]:https://github.com/puma/puma/pull/2742 "PR by @MSP-Greg, merged 2021-12-12"
1867
+ [#2730]:https://github.com/puma/puma/pull/2730 "PR by @kares, merged 2021-11-01"
1868
+ [#2702]:https://github.com/puma/puma/pull/2702 "PR by @jacobherrington, merged 2021-09-21"
1869
+ [#2610]:https://github.com/puma/puma/pull/2610 "PR by @ye-lin-aung, merged 2021-08-18"
1870
+ [#2257]:https://github.com/puma/puma/issues/2257 "Issue by @nateberkopec, closed 2021-08-18"
1871
+ [#2654]:https://github.com/puma/puma/pull/2654 "PR by @Roguelazer, merged 2021-09-07"
1872
+ [#2651]:https://github.com/puma/puma/issues/2651 "Issue by @Roguelazer, closed 2021-09-07"
1873
+ [#2689]:https://github.com/puma/puma/pull/2689 "PR by @jacobherrington, merged 2021-09-05"
1874
+ [#2700]:https://github.com/puma/puma/pull/2700 "PR by @ioquatix, merged 2021-09-16"
1875
+ [#2699]:https://github.com/puma/puma/issues/2699 "Issue by @ioquatix, closed 2021-09-16"
1876
+ [#2690]:https://github.com/puma/puma/pull/2690 "PR by @doits, merged 2021-09-06"
1877
+ [#2688]:https://github.com/puma/puma/pull/2688 "PR by @jdelStrother, merged 2021-09-03"
1878
+ [#2687]:https://github.com/puma/puma/issues/2687 "Issue by @jdelStrother, closed 2021-09-03"
1879
+ [#2675]:https://github.com/puma/puma/pull/2675 "PR by @devwout, merged 2021-09-08"
1880
+ [#2657]:https://github.com/puma/puma/pull/2657 "PR by @olivierbellone, merged 2021-07-13"
1881
+ [#2648]:https://github.com/puma/puma/pull/2648 "PR by @MSP-Greg, merged 2021-06-27"
1882
+ [#1412]:https://github.com/puma/puma/issues/1412 "Issue by @x-yuri, closed 2021-06-27"
1883
+ [#2586]:https://github.com/puma/puma/pull/2586 "PR by @MSP-Greg, merged 2021-05-26"
1884
+ [#2569]:https://github.com/puma/puma/issues/2569 "Issue by @tarragon, closed 2021-05-26"
1885
+ [#2643]:https://github.com/puma/puma/pull/2643 "PR by @MSP-Greg, merged 2021-06-27"
1886
+ [#2638]:https://github.com/puma/puma/issues/2638 "Issue by @gingerlime, closed 2021-06-27"
1887
+ [#2642]:https://github.com/puma/puma/pull/2642 "PR by @MSP-Greg, merged 2021-06-16"
1888
+ [#2633]:https://github.com/puma/puma/pull/2633 "PR by @onlined, merged 2021-06-04"
1889
+ [#2656]:https://github.com/puma/puma/pull/2656 "PR by @olivierbellone, merged 2021-07-07"
1890
+ [#2666]:https://github.com/puma/puma/pull/2666 "PR by @MSP-Greg, merged 2021-07-25"
1891
+ [#2630]:https://github.com/puma/puma/pull/2630 "PR by @seangoedecke, merged 2021-05-20"
1892
+ [#2626]:https://github.com/puma/puma/issues/2626 "Issue by @rorymckinley, closed 2021-05-20"
1893
+ [#2629]:https://github.com/puma/puma/pull/2629 "PR by @ye-lin-aung, merged 2021-05-20"
1894
+ [#2628]:https://github.com/puma/puma/pull/2628 "PR by @wjordan, merged 2021-05-20"
1895
+ [#2625]:https://github.com/puma/puma/issues/2625 "Issue by @jarthod, closed 2021-05-11"
1749
1896
  [#2564]:https://github.com/puma/puma/pull/2564 "PR by @MSP-Greg, merged 2021-04-24"
1750
1897
  [#2526]:https://github.com/puma/puma/issues/2526 "Issue by @nerdrew, closed 2021-04-24"
1751
1898
  [#2559]:https://github.com/puma/puma/pull/2559 "PR by @ylecuyer, merged 2021-03-11"
@@ -1760,11 +1907,11 @@ be added back in a future date when a java Puma::MiniSSL is added.
1760
1907
  [#2605]:https://github.com/puma/puma/pull/2605 "PR by @pascalbetz, merged 2021-04-26"
1761
1908
  [#2584]:https://github.com/puma/puma/issues/2584 "Issue by @kaorihinata, closed 2021-04-26"
1762
1909
  [#2607]:https://github.com/puma/puma/pull/2607 "PR by @calvinxiao, merged 2021-04-23"
1763
- [#2552]:https://github.com/puma/puma/issues/2552 "Issue by @feliperaul, opened 2021-02-09"
1910
+ [#2552]:https://github.com/puma/puma/issues/2552 "Issue by @feliperaul, closed 2021-05-24"
1764
1911
  [#2606]:https://github.com/puma/puma/pull/2606 "PR by @wjordan, merged 2021-04-20"
1765
1912
  [#2574]:https://github.com/puma/puma/issues/2574 "Issue by @darkhelmet, closed 2021-04-20"
1766
- [#2567]:https://github.com/puma/puma/pull/2567 "PR by @kddeisz, merged 2021-04-19"
1767
- [#2566]:https://github.com/puma/puma/issues/2566 "Issue by @kddeisz, closed 2021-04-19"
1913
+ [#2567]:https://github.com/puma/puma/pull/2567 "PR by @kddnewton, merged 2021-04-19"
1914
+ [#2566]:https://github.com/puma/puma/issues/2566 "Issue by @kddnewton, closed 2021-04-19"
1768
1915
  [#2596]:https://github.com/puma/puma/pull/2596 "PR by @MSP-Greg, merged 2021-04-18"
1769
1916
  [#2588]:https://github.com/puma/puma/pull/2588 "PR by @dentarg, merged 2021-04-02"
1770
1917
  [#2556]:https://github.com/puma/puma/issues/2556 "Issue by @gamecreature, closed 2021-04-02"
data/LICENSE CHANGED
File without changes
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  <img src="https://puma.io/images/logos/puma-logo-large.png">
3
3
  </p>
4
4
 
5
- # Puma: A Ruby Web Server Built For Concurrency
5
+ # Puma: A Ruby Web Server Built For Parallelism
6
6
 
7
7
  [![Actions MRI](https://github.com/puma/puma/workflows/MRI/badge.svg?branch=master)](https://github.com/puma/puma/actions?query=workflow%3AMRI)
8
8
  [![Actions non MRI](https://github.com/puma/puma/workflows/non_MRI/badge.svg?branch=master)](https://github.com/puma/puma/actions?query=workflow%3Anon_MRI)
@@ -10,11 +10,11 @@
10
10
  [![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=puma&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=puma&package-manager=bundler&version-scheme=semver)
11
11
  [![StackOverflow](https://img.shields.io/badge/stackoverflow-Puma-blue.svg)]( https://stackoverflow.com/questions/tagged/puma )
12
12
 
13
- Puma is a **simple, fast, multi-threaded, and highly concurrent HTTP 1.1 server for Ruby/Rack applications**.
13
+ Puma is a **simple, fast, multi-threaded, and highly parallel HTTP 1.1 server for Ruby/Rack applications**.
14
14
 
15
- ## Built For Speed &amp; Concurrency
15
+ ## Built For Speed &amp; Parallelism
16
16
 
17
- 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 concurrent Ruby implementations (JRuby, Rubinius) will use all available CPU cores.
17
+ 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.
18
18
 
19
19
  Originally designed as a server for [Rubinius](https://github.com/rubinius/rubinius), Puma also works well with Ruby (MRI) and JRuby.
20
20
 
@@ -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,6 +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
  ```
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.
198
+
199
+ Puma automatically configures SSL when the [`localhost`] gem is loaded in a `development` environment:
200
+
201
+ ```ruby
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:
212
+ require './app'
213
+ require 'localhost'
214
+ run Sinatra::Application
215
+ ```
216
+
217
+ Additionally, Puma must be listening to an SSL socket:
218
+
219
+ ```shell
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
224
+ ```
225
+
226
+ [`localhost`]: https://github.com/socketry/localhost
190
227
 
191
228
  #### Controlling SSL Cipher Suites
192
229
 
@@ -255,11 +292,15 @@ You can also provide a configuration file with the `-C` (or `--config`) flag:
255
292
  $ puma -C /path/to/config
256
293
  ```
257
294
 
258
- If no configuration file is specified, Puma will look for a configuration file at `config/puma.rb`. If an environment is specified, either via the `-e` and `--environment` flags, or through the `RACK_ENV` or the `RAILS_ENV` environment variables, Puma first looks for configuration at `config/puma/<environment_name>.rb`, and then falls back to `config/puma.rb`.
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`.
259
296
 
260
- If you want to prevent Puma from looking for a configuration file in those locations, provide a dash as the argument to the `-C` (or `--config`) flag:
297
+ If you want to prevent Puma from looking for a configuration file in those locations, include the `--no-config` flag:
261
298
 
262
299
  ```
300
+ $ puma --no-config
301
+
302
+ # or
303
+
263
304
  $ puma -C "-"
264
305
  ```
265
306
 
data/bin/puma-wild CHANGED
File without changes
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, processing requests across a TCP or UNIX socket.
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 a thread (in the [`Reactor`](../lib/puma/reactor.rb) class). The connection, once fully buffered and read, moves in to the `todo` list, where it will be picked up by a free/waiting thread in the threadpool (the [`ThreadPool`](../lib/puma/thread_pool.rb) class).
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 process is booted. In cluster mode, a `master` process is booted, which prepares (and may boot) the application, and then uses the `fork()` system call to create 1 or more `child` processes. These `child` processes all listen to the same socket. The `master` process does not listen to the socket or process requests - its purpose is mostly to manage and listen for UNIX signals and possibly kill or boot `child` processes.
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) _workers_, and we sometimes call the threads created by Puma's [`ThreadPool`](../lib/puma/thread_pool.rb) _worker threads_.
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 (with a default of 1024). This determines the size of the queue for unaccepted connections. Generally, this setting is unimportant and will never be hit in production use. If the backlog is full, the connection will be refused by the operating system.
22
- * This socket backlog is distinct from the `backlog` of work as reported by `Puma.stats` or the control server. The backlog as reported by Puma is the number of connections in the process' `todo` set waiting for a thread from the [`ThreadPool`](../lib/puma/thread_pool.rb).
23
- * By default, a single, separate thread (created by the [`Reactor`](../lib/puma/reactor.rb) class) is used to read and buffer requests from the socket.
24
- * When at least one worker thread is available for work, the reactor thread listens to the socket and accepts a request, if one is waiting.
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
- * The time spent waiting for the HTTP request body to be received is exposed to the Rack app as `env['puma.request_body_wait']` (milliseconds).
27
- * Once fully buffered and received, the connection is pushed into the "todo" set.
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 application. The Rack application generates the HTTP response.
30
- * The worker thread writes the response to the connection. Note that while Puma buffers requests via a separate thread, it does not use a separate thread for responses.
31
- * Once done, the thread become available to process another connection in the "todo" set.
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 thread used to buffer requests as described above.
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 for the request to arrive.
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 immediately, and a worker will synchronously do any waiting necessary to read the HTTP request from the socket.
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.
@@ -1,10 +1,12 @@
1
1
  # Compile Options
2
2
 
3
- There are some `cflags` provided to change Puma's default configuration for its C extension.
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 adjust it to allow accept larger queries in GET requests.
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 is software that is expected to be run in a deployed environment eventually.
4
- You can certainly use it as your dev server only, but most people look to use
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 is meant to serve as a foundation of wisdom how to do that
8
- in a way that increases happiness and decreases downtime.
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 want to do this by putting `gem "puma"` into their Gemfile, so we'll
13
- go ahead and assume that. Go add it now... we'll wait.
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
- Welcome back!
14
+ ## Single vs. Cluster mode
16
15
 
17
- ## Single vs Cluster mode
16
+ Initially, Puma was conceived as a thread-only web server, but support for
17
+ processes was added in version 2.
18
18
 
19
- Puma was originally conceived as a thread-only web server, but grew the ability to
20
- also use processes in version 2.
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
- To run `puma` in single mode (e.g. for a development environment) you will need to
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 cpu cores
30
- in the machine, minimum 2.
31
- * Set the number of threads to desired concurrent requests / number of workers.
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 safety of your app, you can tune the
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,69 +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 a time.
52
- But since so many apps are waiting on IO from DBs, etc., they can utilize threads
53
- to make better use of the process.
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
- The rule of thumb is you never want processes that are pegged all the time. This
56
- means that there is more work to do than the process can get through. On the other
57
- hand, if you have processes that sit around doing nothing, then they're just eating
58
- up resources.
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. This means
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 (eg. nginx or haproxy), it's
66
- possible to get an indication of how long requests have been waiting for a Puma
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 t=%[date()]%[date_us()]`
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 `X-Request-Start`.
74
- * To improve accuracy, you will want to subtract time spent waiting for slow clients:
75
- * `env['puma.request_body_wait']` contains the number of milliseconds Puma spent
76
- waiting for the client to send the request body.
77
- * haproxy: `%Th` (TLS handshake time) and `%Ti` (idle time before request) can
78
- can also be added as headers.
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
- Daemonization was removed in Puma 5.0. For alternatives, continue reading.
82
+ The Puma 5.0 release removed daemonization. For older versions and alternatives,
83
+ continue reading.
83
84
 
84
- I prefer to not daemonize my servers and use something like `runit` or `systemd` 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
- puma does not require daemonization to do zero-downtime restarts.
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 capistrano
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 puma stays up in
92
- this scenario! You're just waiting for something weird to happen, puma to die,
93
- and to get paged at 3am. Do yourself a favor, at least the process monitoring
94
- your OS comes with, be it `sysvinit` or `systemd`. Or branch out
95
- and use `runit` or hell, even `monit`.
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
- puma to start running that new code. Minimizing the amount of time the server
101
- is unavailable would be nice as well. Here's how to do it:
102
-
103
- 1. Don't use `preload!`. This dirties the master process and means it will have
104
- to shutdown all the workers and re-exec itself to get your new code. It is not compatible with phased-restart and `prune_bundler` as well.
105
-
106
- 1. Use `prune_bundler`. This makes it so that the cluster master will detach itself
107
- from a Bundler context on start. This allows the cluster workers to load your app
108
- and start a brand new Bundler context within the worker only. This means your
109
- master remains pristine and can live on between new releases of your code.
110
-
111
- 1. Use phased-restart (`SIGUSR1` or `pumactl phased-restart`). This tells the master
112
- to kill off one worker at a time and restart them in your new code. This minimizes
113
- downtime and staggers the restart nicely. **WARNING** This means that both your
114
- old code and your new code will be running concurrently. Most deployment solutions
115
- already cause that, but it's worth warning you about it again. Be careful with your
116
- migrations, etc!
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/fork_worker.md CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
data/docs/kubernetes.md CHANGED
File without changes
data/docs/nginx.md CHANGED
File without changes