puma 8.0.3-java → 8.1.1-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +125 -0
  3. data/README.md +28 -378
  4. data/docs/binding.md +135 -0
  5. data/docs/cluster_mode.md +241 -0
  6. data/docs/configuration.md +78 -0
  7. data/docs/{stats.md → control_server.md} +28 -8
  8. data/docs/{deployment.md → deployment/README.md} +23 -7
  9. data/docs/{kubernetes.md → deployment/kubernetes.md} +4 -4
  10. data/docs/{systemd.md → deployment/systemd.md} +4 -2
  11. data/docs/plugins.md +62 -3
  12. data/docs/puma_support.md +92 -0
  13. data/docs/rails_dev_mode.md +2 -2
  14. data/docs/restart.md +8 -3
  15. data/docs/signals.md +4 -2
  16. data/docs/{5.0-Upgrade.md → upgrading/5.0-Upgrade.md} +3 -3
  17. data/docs/{6.0-Upgrade.md → upgrading/6.0-Upgrade.md} +3 -3
  18. data/docs/{7.0-Upgrade.md → upgrading/7.0-Upgrade.md} +2 -2
  19. data/docs/{8.0-Upgrade.md → upgrading/8.0-Upgrade.md} +4 -4
  20. data/lib/puma/binder.rb +29 -0
  21. data/lib/puma/cli.rb +6 -0
  22. data/lib/puma/client.rb +75 -29
  23. data/lib/puma/client_env.rb +32 -18
  24. data/lib/puma/cluster/worker.rb +109 -33
  25. data/lib/puma/cluster/worker_handle.rb +16 -0
  26. data/lib/puma/cluster.rb +173 -45
  27. data/lib/puma/commonlogger.rb +3 -3
  28. data/lib/puma/configuration.rb +22 -3
  29. data/lib/puma/const.rb +11 -9
  30. data/lib/puma/dsl.rb +265 -91
  31. data/lib/puma/launcher.rb +6 -4
  32. data/lib/puma/minissl.rb +2 -5
  33. data/lib/puma/plugin/systemd.rb +1 -1
  34. data/lib/puma/puma_http11.jar +0 -0
  35. data/lib/puma/response.rb +13 -5
  36. data/lib/puma/runner.rb +5 -1
  37. data/lib/puma/sd_notify.rb +4 -1
  38. data/lib/puma/server.rb +45 -20
  39. data/lib/puma/thread_pool.rb +12 -1
  40. data/lib/puma.rb +1 -1
  41. metadata +17 -34
  42. data/docs/fork_worker.md +0 -41
  43. data/docs/grpc.md +0 -62
  44. data/docs/jungle/README.md +0 -9
  45. data/docs/testing_benchmarks_local_files.md +0 -150
  46. data/docs/testing_test_rackup_ci_files.md +0 -36
  47. data/ext/puma_http11/PumaHttp11Service.java +0 -17
  48. data/ext/puma_http11/extconf.rb +0 -65
  49. data/ext/puma_http11/http11_parser.c +0 -1057
  50. data/ext/puma_http11/http11_parser.h +0 -65
  51. data/ext/puma_http11/http11_parser.java.rl +0 -131
  52. data/ext/puma_http11/http11_parser.rl +0 -149
  53. data/ext/puma_http11/http11_parser_common.rl +0 -54
  54. data/ext/puma_http11/mini_ssl.c +0 -859
  55. data/ext/puma_http11/no_ssl/PumaHttp11Service.java +0 -15
  56. data/ext/puma_http11/org/jruby/puma/EnvKey.java +0 -241
  57. data/ext/puma_http11/org/jruby/puma/Http11.java +0 -321
  58. data/ext/puma_http11/org/jruby/puma/Http11Parser.java +0 -441
  59. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +0 -519
  60. data/ext/puma_http11/puma_http11.c +0 -500
  61. data/tools/Dockerfile +0 -26
  62. data/tools/trickletest.rb +0 -44
  63. /data/docs/{nginx.md → deployment/nginx.md} +0 -0
  64. /data/docs/{jungle → deployment}/rc.d/README.md +0 -0
  65. /data/docs/{jungle → deployment}/rc.d/puma +0 -0
  66. /data/docs/{jungle → deployment}/rc.d/puma.conf +0 -0
data/docs/plugins.md CHANGED
@@ -1,4 +1,4 @@
1
- ## Plugins
1
+ # Plugins
2
2
 
3
3
  Puma 3.0 added support for plugins that can augment configuration and service
4
4
  operations.
@@ -14,7 +14,7 @@ There are two canonical plugins to aid in the development of new plugins:
14
14
  Plugins are activated in a Puma configuration file (such as `config/puma.rb`)
15
15
  by adding `plugin "name"`, such as `plugin "heroku"`.
16
16
 
17
- Plugins are activated based on path requirements so, activating the `heroku`
17
+ Plugins are activated based on path requirements, so activating the `heroku`
18
18
  plugin is much like `require "puma/plugin/heroku"`. This allows gems to provide
19
19
  multiple plugins (as well as unrelated gems to provide Puma plugins).
20
20
 
@@ -39,4 +39,63 @@ public API for plugins.
39
39
 
40
40
  ## Binder hooks
41
41
 
42
- There's `Puma::Binder#before_parse` method that allows to add proc to run before the body of `Puma::Binder#parse`. Example of usage can be found in [that repository](https://github.com/anchordotdev/puma-acme/blob/v0.1.3/lib/puma/acme/plugin.rb#L97-L118) (`before_parse_hook` could be renamed `before_parse`, making monkey patching of [binder.rb](https://github.com/anchordotdev/puma-acme/blob/v0.1.3/lib/puma/acme/binder.rb) is unnecessary).
42
+ There's a `Puma::Binder#before_parse` method that allows adding a proc to run before the body of `Puma::Binder#parse`. Example of usage can be found in [that repository](https://github.com/anchordotdev/puma-acme/blob/v0.1.3/lib/puma/acme/plugin.rb#L97-L118) (`before_parse_hook` could be renamed `before_parse`, making monkey patching of [binder.rb](https://github.com/anchordotdev/puma-acme/blob/v0.1.3/lib/puma/acme/binder.rb) unnecessary).
43
+
44
+ ## Community plugins
45
+
46
+ * [puma-metrics](https://github.com/harmjanblok/puma-metrics) — export Puma metrics to Prometheus
47
+ * [puma-plugin-statsd](https://github.com/yob/puma-plugin-statsd) — send Puma metrics to statsd
48
+ * [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.
49
+ * [puma-plugin-telemetry](https://github.com/babbel/puma-plugin-telemetry) - telemetry plugin for Puma offering various targets to publish
50
+ * [puma-acme](https://github.com/anchordotdev/puma-acme) - automatic SSL/HTTPS certificate provisioning and setup
51
+
52
+ ## Example: stopping Puma via Redis
53
+
54
+ ```ruby
55
+ require 'puma/plugin'
56
+ require 'redis'
57
+
58
+ # How to stop Puma on Heroku
59
+ # - You can't use normal methods because the dyno is not accessible
60
+ # - There's no file system, no way to send signals
61
+ # but ...
62
+ # - You can use Redis or Memcache; any network distributed key-value
63
+ # store
64
+
65
+ # 1. Add this plugin to your 'lib' directory
66
+ # 2. In the `puma.rb` config file add the following lines
67
+ # === Plugins ===
68
+ # require './lib/puma/plugin/redis_stop_puma'
69
+ # plugin 'redis_stop_puma'
70
+ # 3. Now, when you set the redis key "puma::restart::web.1", your web.1 dyno
71
+ # will restart
72
+ # 4. Sniffing the Heroku logs for R14 errors is application (and configuration)
73
+ # specific. I use the Logentries service, watch for the pattern and the call
74
+ # a webhook back into my app to set the Redis key. YMMV
75
+
76
+ # You can test this locally by setting the DYNO environment variable when
77
+ # when starting puma, e.g. `DYNO=pants.1 puma`
78
+
79
+ Puma::Plugin.create do
80
+ def start(launcher)
81
+
82
+ hostname = ENV['DYNO']
83
+ return unless hostname
84
+
85
+ redis = Redis.new(url: ENV.fetch('REDIS_URL', nil))
86
+ return unless redis.ping == 'PONG'
87
+
88
+ in_background do
89
+ while true
90
+ sleep 2
91
+ if message = redis.get("puma::restart::#{hostname}")
92
+ redis.del("puma::restart::#{hostname}")
93
+ $stderr.puts message
94
+ launcher.stop
95
+ break
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
101
+ ```
@@ -0,0 +1,92 @@
1
+ # Puma Support Policy
2
+
3
+ ## What
4
+
5
+ This document's purpose is to help users and contributors of this library make future plans based on the trajectory of this project. It is loosely worded and should be expected to change over time. Maintainers and contributors are encouraged to follow the guidance here but are not strictly bound by it.
6
+
7
+ ## What does "supported" mean?
8
+
9
+ Puma is a community-run project. "Support" means "what do the maintainers pay attention to and what are they likely to merge", and doesn't mean that we do anything by any particular date, or even at all. We may all jet off to a private island tomorrow and never speak again.
10
+
11
+ But, if we do decide to keep devoting our free time to open source software, we will **support the Ruby versions, Ruby implementations, Rack versions, and operating systems which run on our CI**, in any combination, even combinations that CI doesn't run directly.
12
+
13
+ If you open a PR or bug report for a combination of those factors outside of our CI matrix, we may still accept it if it's a small and low-risk fix.
14
+
15
+ We may add environments to CI at any time, but we only drop a supported environment in a minor or major release.
16
+
17
+ ## CI matrix
18
+
19
+ CI aims for the most coverage with the fewest jobs.
20
+
21
+ Every OS and architecture runs the oldest supported Ruby on its oldest runner image, and the newest Ruby on its newest image.
22
+
23
+ On x64, a few more jobs fill in the gaps:
24
+
25
+ - The newest Ubuntu image that can build every supported Ruby runs all of them.
26
+ - The newest Ubuntu image also runs Ruby head with YJIT, plus JRuby and TruffleRuby and their head versions.
27
+ - The newest Windows image also runs the ucrt and mswin builds.
28
+ - The oldest Ubuntu and Windows images also run the oldest Ruby without SSL.
29
+ - The oldest Ubuntu image also runs the oldest Ruby with the oldest supported Rack.
30
+
31
+ ## Puma release support policy
32
+
33
+ By default, Puma supports one release version, the latest release. That means if there is a bug in 3.2.1 (made-up numbers for example only), but the latest release is 4.3.2, the bug must be reproduced in 4.3.2 to qualify for support.
34
+
35
+ When a new major (and sometimes minor) version is released, Puma maintainers will try to preserve the status of the old version via branches and/or tags. Puma maintainers can choose to backport fixes to older versions and cut a release of older versions, but this behavior should not be assumed.
36
+
37
+ If a bug report cannot be reproduced with the latest Puma version, it may be closed.
38
+
39
+ ## Ruby version support policy
40
+
41
+ "Ruby version" refers to the https://github.com/ruby/ruby implementation. Puma also supports other Ruby implementations (the origin of Puma involves an alternate Ruby implementation, Rubinius); see below.
42
+
43
+ Ruby upstream support is documented at https://www.ruby-lang.org/en/downloads/branches/. A "minor" version is X.Y, with X.Y.Z being a patch release. Puma supports every Ruby minor version that is not EOL upstream. Puma may also continue to support older, EOL Ruby versions; the gemspec's `required_ruby_version` declares the oldest supported version. Maintainers decide when to raise that minimum. The Puma team recommends you always use the latest Ruby release.
44
+
45
+ When Puma supports a Ruby version, it will include that version in the CI matrix. CI runs only the most recent patch version of each supported Ruby minor version. If a bug is reported, the report must be reproducible using the most recent patch version of a currently supported Ruby minor version.
46
+
47
+ Puma may rely on upstream support to fix bugs in Ruby rather than working around them. That means, if a bug exists only in a Ruby version that is EOL upstream, it may be closed (it's not guaranteed that we will work around legacy Ruby issues).
48
+
49
+ When Puma does work around a bug in a specific Ruby patch version, the workaround stays until Puma drops support for that Ruby minor version.
50
+
51
+ ## Alternate implementations of Ruby (version support policy)
52
+
53
+ An example of an "alternate" implementation of Ruby is JRuby. Ruby implementations typically target a specific "spec" of ruby/ruby, for example, JRuby 10.0 targets ruby/ruby version 3.4. The target version of a supported implementation must be within the above "Ruby version support policy." Additionally, the implementation release must be supported upstream.
54
+
55
+ Puma supports the JRuby implementation. Puma supports the TruffleRuby implementation.
56
+
57
+ ## Rack (and SPEC) version support
58
+
59
+ From the current Rack documentation https://github.com/rack/rack?tab=readme-ov-file#version-support, Rack lists support levels to be:
60
+
61
+ - Bug fixes and security patches
62
+ - Security patches only
63
+ - End of support
64
+
65
+ Puma will support any Rack version that still accepts "bug fixes" in addition to security patches. Rack versions that receive only security patches, or are at end of support, are not supported.
66
+
67
+ Due to the need to support "hot" reloading applications (via phased restart) which might have different Rack versions, [Puma cannot directly declare the minimum Rack version](https://github.com/puma/puma/commit/537bc21593182cd9c4c0079a3936d05b1f91fe14). Puma may use runtime or boot time checks to warn or error about Rack version support.
68
+
69
+ ## Bundler version support
70
+
71
+ Puma supports the Bundler version that ships with each supported Ruby version.
72
+
73
+ ## How to use this document
74
+
75
+ You can use the guidelines here to make suggestions to contributors (anyone reporting an issue, helping with via a comment, or opening a PR) or maintainers. For example, "I could not reproduce your issue using a currently supported Ruby version. Can you please update to version X.Y and verify the issue persists?" Please link to this doc, state what action you're requesting, and why you feel that action is supported by this document. Please act in "good faith" and do not "bikeshed" (the practice of focusing on non-structural or seemingly irrelevant details).
76
+
77
+ ## How to update this document?
78
+
79
+ Generally, you shouldn't suggest changes to policies in this document unless you have committed to the Puma project.
80
+
81
+ Non-committers:
82
+
83
+ - Spelling fixes are fine; do not re-grammar or "refactor" the wording.
84
+ - Updating stale details derived from the policies is fine. For example, if a canonical URL changes or if specific upstream versions are listed.
85
+
86
+ Committers:
87
+
88
+ - Suggest whatever policy changes you feel are appropriate.
89
+ - Suggest improvements to the wording or consistency or presentation of information.
90
+ - Do not merge policy changes without oversight of other "significant" contributors.
91
+ - When reviewing a policy change, please mark comments as either blocking or non/blocking. Please try to make blocking comments either satisfiable or falsifiable.
92
+
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## "Loopback requests"
4
4
 
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.
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
 
@@ -25,4 +25,4 @@ do_something_with response
25
25
 
26
26
  #### 2. Use multiple processes on Puma
27
27
 
28
- Alternatively, you may also enable multiple (single-threaded) workers on Puma. By doing so, you are sidestepping the problem by creating multiple processes rather than new threads. However, this workaround is not ideal because debugging tools such as [byebug](https://github.com/deivid-rodriguez/byebug/issues/487) and [pry](https://github.com/pry/pry/issues/2153), work poorly with any multi-process web server.
28
+ Alternatively, you may also enable multiple (single-threaded) workers on Puma. By doing so, you are sidestepping the problem by creating multiple processes rather than new threads. However, this workaround is not ideal because debugging tools such as [byebug](https://github.com/deivid-rodriguez/byebug/issues/487) and [pry](https://github.com/pry/pry/issues/2153) work poorly with any multi-process web server.
data/docs/restart.md CHANGED
@@ -1,4 +1,8 @@
1
- Puma provides three distinct kinds of restart operations, each for different use cases. This document describes "hot restarts" and "phased restarts." The third kind of restart operation is called "refork" and is described in the documentation for [`fork_worker`](fork_worker.md).
1
+ # Restart
2
+
3
+ Puma includes the ability to restart itself. When available (MRI, Rubinius, JRuby), Puma performs a "hot restart". This is the same functionality available in *Unicorn* and *NGINX* which keep the server sockets open between restarts. This makes sure that no pending requests are dropped while the restart is taking place.
4
+
5
+ Puma provides three distinct kinds of restart operations, each for different use cases. This document describes "hot restarts" and "phased restarts." The third kind of restart operation is called "refork" and is described in the documentation for [`fork_worker` and `mold_worker`](cluster_mode.md#fork-worker-cluster-mode-experimental).
2
6
 
3
7
  ## Hot restart
4
8
 
@@ -27,8 +31,9 @@ Any of the following will cause a Puma server to perform a hot restart:
27
31
 
28
32
  ### Additional notes
29
33
 
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.
34
+ * The newly started Puma process changes its current working directory to the directory specified by the `directory` option. If `directory` is set to a symlink, this is automatically re-evaluated, so this mechanism can be used to upgrade the application.
31
35
  * Only one version of the application is running at a time.
36
+ * Under systemd with `WatchdogSec` set, the watchdog timer keeps running across a hot restart. Puma pings the watchdog as soon as the new master reports readiness, so `WatchdogSec` needs to exceed your application's boot time.
32
37
  * `before_restart` is invoked just before the server shuts down. This can be used to clean up resources (like long-lived database connections) gracefully. Since Ruby 2.0, it is not typically necessary to explicitly close file descriptors on restart. This is because any file descriptor opened by Ruby will have the `FD_CLOEXEC` flag set, meaning that file descriptors are closed on `exec`. `before_restart` is useful, though, if your application needs to perform any more graceful protocol-specific shutdown procedures before closing connections.
33
38
 
34
39
  ## Phased restart
@@ -57,7 +62,7 @@ Any of the following will cause a Puma server to perform a phased restart:
57
62
 
58
63
  ### Additional notes
59
64
 
60
- * When a phased restart begins, the Puma master process changes its current working directory to the directory specified by the `directory` option. If `directory` is set to symlink, this is automatically re-evaluated, so this mechanism can be used to upgrade the application.
65
+ * When a phased restart begins, the Puma master process changes its current working directory to the directory specified by the `directory` option. If `directory` is set to a symlink, this is automatically re-evaluated, so this mechanism can be used to upgrade the application.
61
66
  * On a single server, it's possible that two versions of the application are running concurrently during a phased restart.
62
67
  * `before_restart` is not invoked
63
68
  * Phased restarts can be slow for Puma clusters with many workers. Hot restarts often complete more quickly, but at the cost of increased latency during the restart.
data/docs/signals.md CHANGED
@@ -1,3 +1,5 @@
1
+ # Signals
2
+
1
3
  The [unix signal](https://en.wikipedia.org/wiki/Unix_signal) is a method of sending messages between [processes](https://en.wikipedia.org/wiki/Process_(computing)). When a signal is sent, the operating system interrupts the target process's normal flow of execution. There are standard signals that are used to stop a process, but there are also custom signals that can be used for other purposes. This document is an attempt to list all supported signals that Puma will respond to. In general, signals need only be sent to the master process of a cluster.
2
4
 
3
5
  ## Sending Signals
@@ -40,8 +42,8 @@ Puma cluster responds to these signals:
40
42
  - `USR1`: Restart workers in phases, a rolling restart. This will not reload the configuration file.
41
43
  - `HUP`: Reopen log files defined in `stdout_redirect` configuration parameter. If there is no `stdout_redirect` option provided, it will behave like `INT`.
42
44
  - `INT`: Equivalent of sending Ctrl-C to cluster. Puma will attempt to finish then exit.
43
- - `CHLD`: Reap zombie child processes and wake event loop in `fork_worker` mode.
44
- - `URG`: Refork workers in phases from worker 0 if `fork_worker` option is enabled.
45
+ - `CHLD`: Reap zombie child processes and wake event loop in `fork_worker` and `mold_worker` modes.
46
+ - `URG`: Refork workers in phases from worker 0 if `fork_worker` option is enabled, or from a newly promoted mold if `mold_worker` option is enabled.
45
47
  - `INFO` (or `PWR` for systems without `INFO`) print backtraces of all puma threads (if supported on your platform).
46
48
 
47
49
  ## Callbacks order in case of different signals
@@ -10,7 +10,7 @@ Puma 5 brings new experimental performance features, a few quality-of-life featu
10
10
  2. Upgrade to version 5.0 in your Gemfile and deploy.
11
11
  3. Try the new performance experiments outlined below and report your results back to the Puma issue tracker.
12
12
 
13
- Puma 5 was named Spoony Bard by our newest supercontributor, [@wjordan](https://github.com/puma/puma/commits?author=wjordan). Will brought you one of our new perf features for this release, as well as [many other fixes and refactors.](https://github.com/puma/puma/commits?author=wjordan) If you'd like to name a Puma release in the future, take a look at [CONTRIBUTING.md](../CONTRIBUTING.md) and get started helping us out :)
13
+ Puma 5 was named Spoony Bard by our newest supercontributor, [@wjordan](https://github.com/puma/puma/commits?author=wjordan). Will brought you one of our new perf features for this release, as well as [many other fixes and refactors.](https://github.com/puma/puma/commits?author=wjordan) If you'd like to name a Puma release in the future, take a look at [CONTRIBUTING.md](../../CONTRIBUTING.md) and get started helping us out :)
14
14
 
15
15
  Puma 5 also welcomes [@MSP-Greg](https://github.com/puma/puma/commits?author=MSP-Greg) as our newest committer. Greg has been instrumental in improving our CI setup and SSL features. Greg also [named our 4.3.0 release](https://github.com/puma/puma/releases/tag/v4.3.0): Mysterious Traveller.
16
16
 
@@ -70,7 +70,7 @@ Puma 5 introduces an experimental new cluster-mode configuration option, `fork_w
70
70
 
71
71
  It is compatible with phased restarts. It also may improve memory usage because the worker process loads additional code after processing requests.
72
72
 
73
- To learn more about using `refork` and `fork_worker`, see ['Fork Worker'](fork_worker.md).
73
+ To learn more about using `refork` and `fork_worker`, see ['Fork Worker'](../cluster_mode.md#fork-worker-cluster-mode-experimental).
74
74
 
75
75
  ### What else is new?
76
76
 
@@ -89,7 +89,7 @@ To learn more about using `refork` and `fork_worker`, see ['Fork Worker'](fork_w
89
89
  * If you have been using the `--control` CLI option, update your scripts to use `--control-url`.
90
90
  * If you are using `worker_directory` in your config file, change it to `directory`.
91
91
  * If you are running MRI, default thread count on Puma is now 5, not 16. This may change the amount of threads running in your threadpool. We believe 5 is a better default for most Ruby web applications on MRI. Higher settings increase latency by causing GVL contention.
92
- * If you are using a worker count of more than 1, set using `WEB_CONCURRENCY`, Puma will now preload the application by default (disable with `preload_app! false`). We believe this is a better default, but may cause issues in non-Rails applications if you do not have the proper `before` and `after` fork hooks configured. See documentation for your framework. Rails users do not need to change anything. **Please note that it is not possible to use [the phased restart](restart.md) with preloading.**
92
+ * If you are using a worker count of more than 1, set using `WEB_CONCURRENCY`, Puma will now preload the application by default (disable with `preload_app! false`). We believe this is a better default, but may cause issues in non-Rails applications if you do not have the proper `before` and `after` fork hooks configured. See documentation for your framework. Rails users do not need to change anything. **Please note that it is not possible to use [the phased restart](../restart.md) with preloading.**
93
93
  * tcp mode and daemonization have been removed without replacement. For daemonization, please use a modern process management solution, such as systemd or monit.
94
94
  * `connected_port` was renamed to `connected_ports` and now returns an Array, not an Integer.
95
95
 
@@ -9,9 +9,9 @@ Here's what you should do:
9
9
  1. Review the Upgrade section below to look for breaking changes that could affect you.
10
10
  2. Upgrade to version 6.0 in your Gemfile and deploy.
11
11
  3. Open up a new bug issue if you find any problems.
12
- 4. Join us in building Puma! We welcome first-timers. See [CONTRIBUTING.md](../CONTRIBUTING.md).
12
+ 4. Join us in building Puma! We welcome first-timers. See [CONTRIBUTING.md](../../CONTRIBUTING.md).
13
13
 
14
- For a complete list of changes, see [History.md](../History.md).
14
+ For a complete list of changes, see [History.md](../../History.md).
15
15
 
16
16
  ## What's New
17
17
 
@@ -27,7 +27,7 @@ We've improved throughput and latency in Puma 6 in a few areas.
27
27
 
28
28
  ### Experimental Rack 3 Support
29
29
 
30
- [Rack 3 is now out](https://github.com/rack/rack/blob/main/UPGRADE-GUIDE.md) and we've started on Rack 3 support. Please open a bug if you find any incompatibilites.
30
+ [Rack 3 is now out](https://github.com/rack/rack/blob/main/UPGRADE-GUIDE.md) and we've started on Rack 3 support. Please open a bug if you find any incompatibilities.
31
31
 
32
32
  ### Sidekiq 7 Capsules
33
33
 
@@ -7,9 +7,9 @@ Here's what you should do:
7
7
  1. Review the Upgrade section below to look for breaking changes that could affect you.
8
8
  2. Upgrade to version 7.0 in your Gemfile and deploy.
9
9
  3. Open up a new bug issue if you find any problems.
10
- 4. Join us in building Puma! We welcome first-timers. See [CONTRIBUTING.md](../CONTRIBUTING.md).
10
+ 4. Join us in building Puma! We welcome first-timers. See [CONTRIBUTING.md](../../CONTRIBUTING.md).
11
11
 
12
- For a complete list of changes, see [History.md](../History.md).
12
+ For a complete list of changes, see [History.md](../../History.md).
13
13
 
14
14
  ## What's New
15
15
 
@@ -7,9 +7,9 @@ Here's what you should do:
7
7
  1. Review the Upgrade section below to look for breaking changes that could affect you.
8
8
  2. Upgrade to version 8.0 in your Gemfile and deploy.
9
9
  3. Open up a new bug issue if you find any problems.
10
- 4. Join us in building Puma! We welcome first-timers. See [CONTRIBUTING.md](./CONTRIBUTING.md).
10
+ 4. Join us in building Puma! We welcome first-timers. See [CONTRIBUTING.md](../../CONTRIBUTING.md).
11
11
 
12
- For a complete list of changes, see [History.md](./History.md).
12
+ For a complete list of changes, see [History.md](../../History.md).
13
13
 
14
14
  ## What's New
15
15
 
@@ -33,7 +33,7 @@ run lambda { |env|
33
33
  }
34
34
  ```
35
35
 
36
- We anticipate this will mainly by used by framework authors who have threads or types of requests they know are extremely IO-bound, and don't recommend it for use at the application level.
36
+ We anticipate this will mainly be used by framework authors who have threads or types of requests they know are extremely IO-bound, and don't recommend it for use at the application level.
37
37
 
38
38
  **Thread pool limits can be changed at runtime.** Puma now exposes `Puma::Server#update_thread_pool_min_max`, and hook/plugin code can do the same through `Puma::ServerPluginControl`.
39
39
 
@@ -91,7 +91,7 @@ bind 'tcp://0.0.0.0:9292'
91
91
 
92
92
  Check the following list to see if you're depending on any of these behaviors:
93
93
 
94
- 1. Puma will now listen on `::` (IPv6) by default. Previously, it listened to `0.0.0.0` (IPv4). Systems that support both IPv6 and IPv4 (Ubuntu and Mac commonly do) will still support receiving to `0.0.0.0`. See [[the support table in the PR](https://github.com/puma/puma/pull/3847)](https://github.com/puma/puma/pull/3847) for a binding compatibility. For systems that ONLY bind to IPv6 (without IPv4 support) this may be a breaking change. You can overwrite this default behavior by setting `bind 'tcp://0.0.0.0:9292'`, `port ENV.fetch('PORT', 9292), '0.0.0.0'`, or `set_default_host '0.0.0.0'` explicitly to remain IPv4 only. Review any firewall rules, health checks, deploy scripts, or host-string parsing code that assumed `0.0.0.0`, `127.0.0.1`, or unbracketed `HOST:PORT` formatting.
94
+ 1. Puma will now listen on `::` (IPv6) by default. Previously, it listened to `0.0.0.0` (IPv4). Systems that support both IPv6 and IPv4 (Ubuntu and Mac commonly do) will still support receiving to `0.0.0.0`. See [the support table in the PR](https://github.com/puma/puma/pull/3847) for binding compatibility. For systems that ONLY bind to IPv6 (without IPv4 support) this may be a breaking change. You can overwrite this default behavior by setting `bind 'tcp://0.0.0.0:9292'`, `port ENV.fetch('PORT', 9292), '0.0.0.0'`, or `set_default_host '0.0.0.0'` explicitly to remain IPv4 only. Review any firewall rules, health checks, deploy scripts, or host-string parsing code that assumed `0.0.0.0`, `127.0.0.1`, or unbracketed `HOST:PORT` formatting.
95
95
  2. If you explicitly configure `bind 'tcp://[::]:...'`, `bind 'ssl://[::]:...'`, or equivalent `ssl_bind '::', ...`, Puma will now rewrite that unspecified IPv6 bind to `0.0.0.0` when the host has no non-loopback IPv6 interface, and it will warn on boot. If you were using `::` to force IPv6-only behavior or to detect IPv6 availability, switch to a concrete IPv6 address instead of `::`, or ensure the machine actually has a usable IPv6 interface before Puma starts.
96
96
  3. `before_thread_start` hooks now receive a `Puma::ServerPluginControl` argument. Update any zero-arity lambdas, method objects, or other strict-arity hook code to accept one argument, for example `before_thread_start { |_control| ... }`, or Puma can raise `ArgumentError` when the hook runs.
97
97
  4. On platforms without `SIGINFO`, Puma now traps `SIGPWR`, and `pumactl info` sends `SIGPWR` there. If your supervisor, init script, or container tooling already uses `SIGPWR` for something else, change that wiring before upgrading and update any runbooks that assumed Puma would ignore `SIGPWR`.
data/lib/puma/binder.rb CHANGED
@@ -309,6 +309,13 @@ module Puma
309
309
  end
310
310
  end
311
311
 
312
+ # Removes and returns the activated socket for +url+ as <tt>[key, socket]</tt>,
313
+ # or +nil+ if none was activated for it.
314
+ def take_activated_socket(url)
315
+ key = activated_keys_for(url).find { |k| @activated_sockets.key?(k) }
316
+ [key, @activated_sockets.delete(key)] if key
317
+ end
318
+
312
319
  def localhost_authority
313
320
  @localhost_authority ||= Localhost::Authority.fetch if defined?(Localhost::Authority) && !Puma::IS_JRUBY
314
321
  end
@@ -486,6 +493,28 @@ module Puma
486
493
 
487
494
  private
488
495
 
496
+ def activated_keys_for(url)
497
+ uri = URI.parse url
498
+ case uri.scheme
499
+ when "tcp", "ssl"
500
+ [[:tcp, uri.host, uri.port]]
501
+ when "unix"
502
+ path = "#{uri.host}#{uri.path}".gsub("%20", " ")
503
+ return [] if path.start_with?("@")
504
+
505
+ real_path = begin
506
+ File.realdirpath(path)
507
+ rescue SystemCallError
508
+ path
509
+ end
510
+ [[:unix, path], [:unix, real_path]].uniq
511
+ else
512
+ []
513
+ end
514
+ rescue URI::InvalidURIError
515
+ []
516
+ end
517
+
489
518
  # @!attribute [r] loopback_addresses
490
519
  def loopback_addresses
491
520
  t = Socket.ip_address_list.select do |addrinfo|
data/lib/puma/cli.rb CHANGED
@@ -138,6 +138,12 @@ module Puma
138
138
  user_config.fork_worker(*args.compact)
139
139
  end
140
140
 
141
+ o.on "--mold-worker=[REQUESTS]", Array,
142
+ "Fork new workers from a mold promoted from an existing worker. Cluster mode only",
143
+ "Promote a new mold at each comma-separated REQUESTS threshold (default 1000)" do |thresholds|
144
+ user_config.mold_worker(*thresholds)
145
+ end
146
+
141
147
  o.on "-I", "--include PATH", "Specify $LOAD_PATH directories" do |arg|
142
148
  $LOAD_PATH.unshift(*arg.split(':'))
143
149
  end
data/lib/puma/client.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require_relative 'detect'
4
4
  require_relative 'io_buffer'
5
5
  require_relative 'client_env'
6
+ require_relative 'null_io'
6
7
  require 'tempfile'
7
8
 
8
9
  if Puma::IS_JRUBY
@@ -18,6 +19,17 @@ module Puma
18
19
 
19
20
  class HttpParserError501 < IOError; end
20
21
 
22
+ # Raised when a +continue_callback+ answers an <tt>Expect: 100-continue</tt>
23
+ # request itself, so the request body is never read.
24
+ class ContinueRejected < StandardError
25
+ attr_reader :response
26
+
27
+ def initialize(response)
28
+ super("Expect: 100-continue answered by continue_callback")
29
+ @response = response
30
+ end
31
+ end
32
+
21
33
  #———————————————————————— DO NOT USE — this class is for internal use only ———
22
34
 
23
35
 
@@ -46,12 +58,12 @@ module Puma
46
58
  ALLOWED_TRANSFER_ENCODING = %w[compress deflate gzip].freeze
47
59
 
48
60
  # chunked body validation
49
- CHUNK_SIZE_INVALID = /[^\h]/.freeze
61
+ CHUNK_SIZE_VALID = /\A\h+\z/.freeze
50
62
  CHUNK_VALID_ENDING = Const::LINE_END
51
63
  CHUNK_VALID_ENDING_SIZE = CHUNK_VALID_ENDING.bytesize
52
64
 
53
65
  # The maximum number of bytes we'll buffer looking for a valid
54
- # chunk header.
66
+ # chunk header, and the maximum size of a trailer section.
55
67
  MAX_CHUNK_HEADER_SIZE = 4096
56
68
 
57
69
  SHUTDOWN_READ_GRACE = 1
@@ -78,7 +90,8 @@ module Puma
78
90
  :tempfile, :io_buffer, :http_content_length_limit_exceeded,
79
91
  :requests_served, :error_status_code, :bytes_read
80
92
 
81
- attr_writer :peerip, :http_content_length_limit, :supported_http_methods
93
+ attr_writer :peerip, :http_content_length_limit, :supported_http_methods,
94
+ :allow_underscore_headers, :continue_callback
82
95
 
83
96
  attr_accessor :remote_addr_header, :listener, :env_set_http_version,
84
97
  :reactor_error
@@ -108,6 +121,8 @@ module Puma
108
121
 
109
122
  @http_content_length_limit = nil
110
123
  @http_content_length_limit_exceeded = nil
124
+ @allow_underscore_headers = true
125
+ @continue_callback = nil
111
126
  @error_status_code = nil
112
127
  @reactor_error = nil
113
128
 
@@ -354,6 +369,8 @@ module Puma
354
369
  raise e unless HttpParserError === e && e.message.include?('non-SSL')
355
370
 
356
371
  req, _ = @buffer.split "\r\n\r\n"
372
+ raise e if req.nil? || req.empty?
373
+
357
374
  request_line, headers = req.split "\r\n", 2
358
375
 
359
376
  # below checks for request issues and changes error message accordingly
@@ -384,6 +401,7 @@ module Puma
384
401
 
385
402
  # processes the `env` and the request body
386
403
  def process_env_body
404
+ validate_env
387
405
  temp = setup_body
388
406
  normalize_env
389
407
  req_env_post_parse
@@ -496,10 +514,21 @@ module Puma
496
514
  # @return [Boolean] true if the body can be completely read, false otherwise
497
515
  #
498
516
  def setup_body
517
+ # The parsers preserve underscores as commas to distinguish these aliases
518
+ # from real framing headers. Reject them before 100 Continue or body reads,
519
+ # regardless of allow_underscore_headers, to avoid proxy disagreements.
520
+ if @env.key?('HTTP_CONTENT,LENGTH') || @env.key?('HTTP_TRANSFER,ENCODING')
521
+ @error_status_code = 400
522
+ @env[HTTP_CONNECTION] = CLOSE
523
+ raise HttpParserError, 'Underscores are not allowed in HTTP framing headers'
524
+ end
525
+
499
526
  @body_read_start = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
500
527
 
501
528
  if @env[HTTP_EXPECT] == CONTINUE
502
- # TODO allow a hook here to check the headers before going forward
529
+ if @continue_callback && (response = @continue_callback.call(@env))
530
+ reject_continue response
531
+ end
503
532
  write_interim HTTP_11_100
504
533
  end
505
534
 
@@ -704,6 +733,8 @@ module Puma
704
733
  end
705
734
 
706
735
  def decode_chunk(chunk)
736
+ return finish_last_chunk(@prev_chunk + chunk) if @in_last_chunk
737
+
707
738
  if @partial_part_left > 0
708
739
  if @partial_part_left <= chunk.size
709
740
  if @partial_part_left > 2
@@ -739,31 +770,18 @@ module Puma
739
770
  # Puma doesn't process chunk extensions, but should parse if they're
740
771
  # present, which is the reason for the semicolon regex
741
772
  chunk_hex = line.strip[/\A[^;]+/]
742
- if CHUNK_SIZE_INVALID.match? chunk_hex
743
- raise HttpParserError, "Invalid chunk size: '#{chunk_hex}'"
773
+ unless CHUNK_SIZE_VALID.match? chunk_hex
774
+ err_msg = chunk_hex && !chunk_hex.empty? ?
775
+ "Invalid chunk size: '#{chunk_hex}'" :
776
+ "Chunk size cannot be empty or nil"
777
+ raise HttpParserError, err_msg
744
778
  end
779
+
745
780
  len = chunk_hex.to_i(16)
746
781
  if len == 0
747
782
  @in_last_chunk = true
748
783
  @body.rewind
749
- rest = io.read
750
- if rest.bytesize < CHUNK_VALID_ENDING_SIZE
751
- @buffer = nil
752
- @partial_part_left = CHUNK_VALID_ENDING_SIZE - rest.bytesize
753
- return false
754
- else
755
- # if the next character is a CRLF, set buffer to everything after that CRLF
756
- start_of_rest = if rest.start_with?(CHUNK_VALID_ENDING)
757
- CHUNK_VALID_ENDING_SIZE
758
- else # we have started a trailer section, which we do not support. skip it!
759
- rest.index(CHUNK_VALID_ENDING*2) + CHUNK_VALID_ENDING_SIZE*2
760
- end
761
-
762
- @buffer = rest[start_of_rest..-1]
763
- @buffer = nil if @buffer.empty?
764
- set_ready
765
- return true
766
- end
784
+ return finish_last_chunk(io.read)
767
785
  end
768
786
 
769
787
  # Track the excess as a function of the size of the
@@ -816,12 +834,33 @@ module Puma
816
834
  end
817
835
  end
818
836
 
819
- if @in_last_chunk
820
- set_ready
821
- true
822
- else
823
- false
837
+ false
838
+ end
839
+
840
+ # Consume the terminator that ends a chunked body. Per RFC 9112 §7.1.2
841
+ # this is either a bare CRLF or an optional trailer section ending in
842
+ # CRLF*2. Puma does not surface trailers, so we skip past them. Bytes
843
+ # past the terminator belong to the next pipelined request.
844
+ def finish_last_chunk(rest)
845
+ if rest.start_with?(CHUNK_VALID_ENDING)
846
+ trailer_end = CHUNK_VALID_ENDING_SIZE
847
+ elsif idx = rest.index(CHUNK_VALID_ENDING * 2)
848
+ trailer_end = idx + CHUNK_VALID_ENDING_SIZE * 2
849
+ elsif rest.bytesize < MAX_CHUNK_HEADER_SIZE
850
+ @prev_chunk = rest
851
+ return false
852
+ end
853
+
854
+ if trailer_end.nil? || trailer_end > MAX_CHUNK_HEADER_SIZE
855
+ @env[HTTP_CONNECTION] = CLOSE
856
+ raise HttpParserError, "maximum size of chunk trailer exceeded"
824
857
  end
858
+
859
+ @prev_chunk = ""
860
+ @buffer = rest[trailer_end..-1]
861
+ @buffer = nil if @buffer.empty?
862
+ set_ready
863
+ true
825
864
  end
826
865
 
827
866
  def set_ready
@@ -832,6 +871,13 @@ module Puma
832
871
  @ready = true
833
872
  end
834
873
 
874
+ def reject_continue(response)
875
+ @buffer = nil
876
+ @body = EmptyBody
877
+ @env[HTTP_CONNECTION] = 'close'
878
+ raise ContinueRejected, response
879
+ end
880
+
835
881
  def raise_above_http_content_limit
836
882
  @http_content_length_limit_exceeded = true
837
883
  @buffer = nil