puma 5.5.0 → 5.5.1
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 +10 -0
- data/README.md +23 -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 +10 -10
- data/docs/stats.md +8 -8
- data/docs/systemd.md +63 -67
- data/ext/puma_http11/http11_parser.c +19 -12
- data/ext/puma_http11/http11_parser_common.rl +1 -1
- data/ext/puma_http11/org/jruby/puma/Http11Parser.java +34 -34
- data/lib/puma/client.rb +1 -1
- data/lib/puma/cluster/worker.rb +2 -12
- data/lib/puma/cluster.rb +0 -10
- data/lib/puma/configuration.rb +1 -1
- data/lib/puma/const.rb +1 -1
- data/lib/puma/control_cli.rb +1 -1
- data/lib/puma/minissl.rb +1 -1
- data/lib/puma/runner.rb +19 -6
- data/lib/puma/server.rb +6 -6
- data/lib/puma/util.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79c6d8e0b864d27712116c6e235baddf99aaf663d8b152b11287b16ecf2a80a1
|
4
|
+
data.tar.gz: 4fc99948c0655ffc08e3304a758a50b0370553912cc9bf808bed40abc6501458
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d2b50dca388c1ea1494a2c8cf326d159d1e1c8ebdb4d68f4e07a120a10bf623b3545f1b991dce15da6ab0fe8d97b27c1612170dbc2f296bdeca04748268274b
|
7
|
+
data.tar.gz: cfa324c8ce8353ca3454c133c0f10c351c2171a7e355ffec3cd72ba774e97badb1c027d48ea3a7c30472678c528be3a7a8f3f083aa195a88527157ae8223a4b4
|
data/History.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## 5.5.1 / 2021-10-12
|
2
|
+
|
3
|
+
* Security
|
4
|
+
* Do not allow LF as a line ending in a header (CVE-2021-41136)
|
5
|
+
|
1
6
|
## 5.5.0 / 2021-09-19
|
2
7
|
|
3
8
|
* Features
|
@@ -251,6 +256,11 @@
|
|
251
256
|
* Support parallel tests in verbose progress reporting ([#2223])
|
252
257
|
* Refactor error handling in server accept loop ([#2239])
|
253
258
|
|
259
|
+
## 4.3.9 / 2021-10-12
|
260
|
+
|
261
|
+
* Security
|
262
|
+
* Do not allow LF as a line ending in a header (CVE-2021-41136)
|
263
|
+
|
254
264
|
## 4.3.8 / 2021-05-11
|
255
265
|
|
256
266
|
* Security
|
data/README.md
CHANGED
@@ -187,21 +187,38 @@ Need a bit of security? Use SSL sockets:
|
|
187
187
|
```
|
188
188
|
$ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'
|
189
189
|
```
|
190
|
-
#### Self-signed SSL certificates (via
|
190
|
+
#### Self-signed SSL certificates (via the [`localhost`] gem, for development use):
|
191
191
|
|
192
|
-
Puma supports [localhost]
|
192
|
+
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.
|
193
|
+
|
194
|
+
Puma automatically configures SSL when the [`localhost`] gem is loaded in a `development` environment:
|
193
195
|
|
194
196
|
```ruby
|
195
|
-
#
|
197
|
+
# Add the gem to your Gemfile
|
198
|
+
group(:development) do
|
199
|
+
gem 'localhost'
|
200
|
+
end
|
201
|
+
|
202
|
+
# And require it implicitly using bundler
|
203
|
+
require "bundler"
|
204
|
+
Bundler.require(:default, ENV["RACK_ENV"].to_sym)
|
205
|
+
|
206
|
+
# Alternatively, you can require the gem in config.ru:
|
196
207
|
require './app'
|
197
|
-
require 'localhost
|
208
|
+
require 'localhost'
|
198
209
|
run Sinatra::Application
|
210
|
+
```
|
199
211
|
|
200
|
-
|
212
|
+
Additionally, Puma must be listening to an SSL socket:
|
201
213
|
|
214
|
+
```shell
|
202
215
|
$ puma -b 'ssl://localhost:9292' config.ru
|
216
|
+
|
217
|
+
# The following options allow you to reach Puma over HTTP as well:
|
218
|
+
$ puma -b ssl://localhost:9292 -b tcp://localhost:9393 config.ru
|
203
219
|
```
|
204
220
|
|
221
|
+
[`localhost`]: https://github.com/socketry/localhost
|
205
222
|
|
206
223
|
#### Controlling SSL Cipher Suites
|
207
224
|
|
@@ -270,7 +287,7 @@ You can also provide a configuration file with the `-C` (or `--config`) flag:
|
|
270
287
|
$ puma -C /path/to/config
|
271
288
|
```
|
272
289
|
|
273
|
-
If no configuration file is specified, Puma will look for a configuration file at `config/puma.rb`. If an environment is specified
|
290
|
+
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
291
|
|
275
292
|
If you want to prevent Puma from looking for a configuration file in those locations, include the `--no-config` flag:
|
276
293
|
|
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 (with a default of 1024).
|
22
|
-
|
23
|
-
|
24
|
-
|
34
|
+
* The backlog of this socket is configured (with a default of 1024). The
|
35
|
+
backlog determines the size of the queue for unaccepted connections.
|
36
|
+
Generally, you'll never hit the backlog cap in production. If the backlog is
|
37
|
+
full, the operating system refuses 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
|
|
data/docs/restart.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
Puma provides three distinct kinds of restart operations, each for different use cases.
|
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).
|
2
2
|
|
3
3
|
## Hot restart
|
4
4
|
|
5
|
-
To perform a "hot" restart, Puma performs an `exec` operation to start the process up again, so no memory is shared between the old process and the new process. As a result, it is safe to issue a restart any place where you would manually stop Puma and start it again. In particular, it is safe to upgrade Puma itself using a hot restart.
|
5
|
+
To perform a "hot" restart, Puma performs an `exec` operation to start the process up again, so no memory is shared between the old process and the new process. As a result, it is safe to issue a restart at any place where you would manually stop Puma and start it again. In particular, it is safe to upgrade Puma itself using a hot restart.
|
6
6
|
|
7
7
|
If the new process is unable to load, it will simply exit. You should therefore run Puma under a process monitor when using it in production.
|
8
8
|
|
@@ -16,14 +16,14 @@ Any of the following will cause a Puma server to perform a hot restart:
|
|
16
16
|
|
17
17
|
### Supported configurations
|
18
18
|
|
19
|
-
* Works in cluster mode and
|
19
|
+
* Works in cluster mode and single mode
|
20
20
|
* Supported on all platforms
|
21
21
|
|
22
22
|
### Client experience
|
23
23
|
|
24
|
-
* All platforms:
|
24
|
+
* All platforms: clients with an in-flight request are served responses before the connection is closed gracefully. Puma gracefully disconnects any idle HTTP persistent connections before restarting.
|
25
25
|
* On MRI or TruffleRuby on Linux and BSD: Clients who connect just before the server restarts may experience increased latency while the server stops and starts again, but their connections will not be closed prematurely.
|
26
|
-
* On Windows and
|
26
|
+
* On Windows and JRuby: Clients who connect just before a restart may experience "connection reset" errors.
|
27
27
|
|
28
28
|
### Additional notes
|
29
29
|
|
@@ -32,7 +32,7 @@ Any of the following will cause a Puma server to perform a hot restart:
|
|
32
32
|
|
33
33
|
## Phased restart
|
34
34
|
|
35
|
-
Phased restarts replace all running workers in a Puma cluster. This is a useful way to
|
35
|
+
Phased restarts replace all running workers in a Puma cluster. This is a useful way to upgrade the application that Puma is serving gracefully. A phased restart works by first killing an old worker, then starting a new worker, waiting until the new worker has successfully started before proceeding to the next worker. This process continues until all workers are replaced. The master process is not restarted.
|
36
36
|
|
37
37
|
### How-to
|
38
38
|
|
data/docs/signals.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
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.
|
1
|
+
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
2
|
|
3
3
|
## Sending Signals
|
4
4
|
|
5
|
-
If you are new to signals it can be
|
5
|
+
If you are new to signals, it can be helpful to see how they are used. When a process starts in a *nix-like operating system, it will have a [PID - or process identifier](https://en.wikipedia.org/wiki/Process_identifier) that can be used to send signals to the process. For demonstration, we will create an infinitely running process by tailing a file:
|
6
6
|
|
7
7
|
```sh
|
8
8
|
$ echo "foo" >> my.log
|
@@ -10,7 +10,7 @@ $ irb
|
|
10
10
|
> pid = Process.spawn 'tail -f my.log'
|
11
11
|
```
|
12
12
|
|
13
|
-
From here we can see that the tail process is running by using the `ps` command:
|
13
|
+
From here, we can see that the tail process is running by using the `ps` command:
|
14
14
|
|
15
15
|
```sh
|
16
16
|
$ ps aux | grep tail
|
@@ -27,7 +27,7 @@ Process.detach(pid) # https://ruby-doc.org/core-2.1.1/Process.html#method-c-deta
|
|
27
27
|
Process.kill("TERM", pid)
|
28
28
|
```
|
29
29
|
|
30
|
-
Now you will see via `ps` that there is no more `tail` process. Sometimes when referring to signals the `SIG` prefix will be used
|
30
|
+
Now you will see via `ps` that there is no more `tail` process. Sometimes when referring to signals, the `SIG` prefix will be used. For example, `SIGTERM` is equivalent to sending `TERM` via `Process.kill`.
|
31
31
|
|
32
32
|
## Puma Signals
|
33
33
|
|
@@ -35,13 +35,13 @@ Puma cluster responds to these signals:
|
|
35
35
|
|
36
36
|
- `TTIN` increment the worker count by 1
|
37
37
|
- `TTOU` decrement the worker count by 1
|
38
|
-
- `TERM` send `TERM` to worker.
|
39
|
-
- `USR2` restart workers. This also reloads
|
40
|
-
- `USR1` restart workers in phases, a rolling restart. This will not reload configuration file.
|
41
|
-
- `HUP ` reopen log files defined in stdout_redirect configuration parameter. If there is no stdout_redirect option provided it will behave like `INT`
|
42
|
-
- `INT ` equivalent of sending Ctrl-C to cluster.
|
38
|
+
- `TERM` send `TERM` to worker. The worker will attempt to finish then exit.
|
39
|
+
- `USR2` restart workers. This also reloads the Puma configuration file, if there is one.
|
40
|
+
- `USR1` restart workers in phases, a rolling restart. This will not reload the configuration file.
|
41
|
+
- `HUP ` reopen log files defined in stdout_redirect configuration parameter. If there is no stdout_redirect option provided, it will behave like `INT`
|
42
|
+
- `INT ` equivalent of sending Ctrl-C to cluster. Puma will attempt to finish then exit.
|
43
43
|
- `CHLD`
|
44
|
-
- `URG ` refork workers in phases from worker 0
|
44
|
+
- `URG ` refork workers in phases from worker 0 if `fork_workers` option is enabled.
|
45
45
|
|
46
46
|
## Callbacks order in case of different signals
|
47
47
|
|
data/docs/stats.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
##
|
1
|
+
## Accessing stats
|
2
2
|
|
3
3
|
Stats can be accessed in two ways:
|
4
4
|
|
@@ -47,18 +47,18 @@ end
|
|
47
47
|
|
48
48
|
## Explanation of stats
|
49
49
|
|
50
|
-
`Puma.stats` returns different information and a different structure depending on if Puma is in single vs cluster mode. There is one top-level attribute that is common to both modes:
|
50
|
+
`Puma.stats` returns different information and a different structure depending on if Puma is in single vs. cluster mode. There is one top-level attribute that is common to both modes:
|
51
51
|
|
52
|
-
* started_at: when
|
52
|
+
* started_at: when Puma was started
|
53
53
|
|
54
54
|
### single mode and individual workers in cluster mode
|
55
55
|
|
56
|
-
When Puma
|
56
|
+
When Puma runs in single mode, these stats are available at the top level. When Puma runs in cluster mode, these stats are available within the `worker_status` array in a hash labeled `last_status`, in an array of hashes where one hash represents each worker.
|
57
57
|
|
58
58
|
* backlog: requests that are waiting for an available thread to be available. if this is above 0, you need more capacity [always true?]
|
59
59
|
* running: how many threads are running
|
60
|
-
* pool_capacity: the number of requests that the server is capable of taking right now. For example if the number is 5 then it means there are 5 threads sitting idle ready to take a request. If one request comes in, then the value would be 4 until it finishes processing. If the minimum threads allowed is zero, this number will still have a maximum value of the maximum threads allowed.
|
61
|
-
* max_threads: the maximum number of threads
|
60
|
+
* pool_capacity: the number of requests that the server is capable of taking right now. For example, if the number is 5, then it means there are 5 threads sitting idle ready to take a request. If one request comes in, then the value would be 4 until it finishes processing. If the minimum threads allowed is zero, this number will still have a maximum value of the maximum threads allowed.
|
61
|
+
* max_threads: the maximum number of threads Puma is configured to spool per worker
|
62
62
|
* requests_count: the number of requests this worker has served since starting
|
63
63
|
|
64
64
|
|
@@ -72,9 +72,9 @@ When Puma is run in single mode, these stats are available at the top level. Whe
|
|
72
72
|
|
73
73
|
### worker status
|
74
74
|
|
75
|
-
* started_at: when the worker
|
75
|
+
* started_at: when the worker started
|
76
76
|
* pid: the process id of the worker process
|
77
|
-
* index: each worker gets a number. if
|
77
|
+
* index: each worker gets a number. if Puma is configured to have 3 workers, then this will be 0, 1, or 2
|
78
78
|
* booted: if it's done booting [?]
|
79
79
|
* last_checkin: Last time the worker responded to the master process' heartbeat check.
|
80
80
|
* last_status: a hash of info about the worker's state handling requests. See the explanation for this in "single mode and individual workers in cluster mode" section above.
|
data/docs/systemd.md
CHANGED
@@ -1,19 +1,18 @@
|
|
1
1
|
# systemd
|
2
2
|
|
3
|
-
[systemd](https://www.freedesktop.org/wiki/Software/systemd/) is a
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
[systemd](https://www.freedesktop.org/wiki/Software/systemd/) is a commonly
|
4
|
+
available init system (PID 1) on many Linux distributions. It offers process
|
5
|
+
monitoring (including automatic restarts) and other useful features for running
|
6
|
+
Puma in production.
|
7
7
|
|
8
8
|
## Service Configuration
|
9
9
|
|
10
|
-
Below is a sample puma.service configuration file for systemd, which
|
11
|
-
|
12
|
-
|
10
|
+
Below is a sample puma.service configuration file for systemd, which can be
|
11
|
+
copied or symlinked to `/etc/systemd/system/puma.service`, or if desired, using
|
12
|
+
an application or instance-specific name.
|
13
13
|
|
14
|
-
Note that this uses the systemd preferred "simple" type where the
|
15
|
-
|
16
|
-
exit).
|
14
|
+
Note that this uses the systemd preferred "simple" type where the start command
|
15
|
+
remains running in the foreground (does not fork and exit).
|
17
16
|
|
18
17
|
~~~~ ini
|
19
18
|
[Unit]
|
@@ -37,8 +36,8 @@ WatchdogSec=10
|
|
37
36
|
# Preferably configure a non-privileged user
|
38
37
|
# User=
|
39
38
|
|
40
|
-
# The path to
|
41
|
-
# Also replace the "<YOUR_APP_PATH>"
|
39
|
+
# The path to your application code root directory.
|
40
|
+
# Also replace the "<YOUR_APP_PATH>" placeholders below with this path.
|
42
41
|
# Example /home/username/myapp
|
43
42
|
WorkingDirectory=<YOUR_APP_PATH>
|
44
43
|
|
@@ -64,33 +63,31 @@ Restart=always
|
|
64
63
|
WantedBy=multi-user.target
|
65
64
|
~~~~
|
66
65
|
|
67
|
-
See
|
66
|
+
See
|
67
|
+
[systemd.exec](https://www.freedesktop.org/software/systemd/man/systemd.exec.html)
|
68
68
|
for additional details.
|
69
69
|
|
70
70
|
## Socket Activation
|
71
71
|
|
72
|
-
systemd and
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
`Requires` directive for the socket unit in the service file (see
|
92
|
-
above.) Here is a sample puma.socket, matching the ports used in the
|
93
|
-
above puma.service:
|
72
|
+
systemd and Puma also support socket activation, where systemd opens the
|
73
|
+
listening socket(s) in advance and provides them to the Puma master process on
|
74
|
+
startup. Among other advantages, this keeps listening sockets open across puma
|
75
|
+
restarts and achieves graceful restarts, including when upgraded Puma, and is
|
76
|
+
compatible with both clustered mode and application preload.
|
77
|
+
|
78
|
+
**Note:** Any wrapper scripts which `exec`, or other indirections in `ExecStart`
|
79
|
+
may result in activated socket file descriptors being closed before reaching the
|
80
|
+
puma master process. For example, if using `bundle exec`, pass the
|
81
|
+
`--keep-file-descriptors` flag. `bundle exec` can be avoided by using a `puma`
|
82
|
+
executable generated by `bundle binstubs puma`. This is tracked in [#1499].
|
83
|
+
|
84
|
+
**Note:** Socket activation doesn't currently work on JRuby. This is tracked in
|
85
|
+
[#1367].
|
86
|
+
|
87
|
+
Configure one or more `ListenStream` sockets in a companion `*.socket` unit file
|
88
|
+
to use socket activation. Also, uncomment the associated `Requires` directive
|
89
|
+
for the socket unit in the service file (see above.) Here is a sample
|
90
|
+
puma.socket, matching the ports used in the above puma.service:
|
94
91
|
|
95
92
|
~~~~ ini
|
96
93
|
[Unit]
|
@@ -113,31 +110,32 @@ Backlog=1024
|
|
113
110
|
WantedBy=sockets.target
|
114
111
|
~~~~
|
115
112
|
|
116
|
-
See
|
113
|
+
See
|
114
|
+
[systemd.socket](https://www.freedesktop.org/software/systemd/man/systemd.socket.html)
|
117
115
|
for additional configuration details.
|
118
116
|
|
119
|
-
Note that the above configurations will work with Puma in either
|
120
|
-
|
117
|
+
Note that the above configurations will work with Puma in either single process
|
118
|
+
or cluster mode.
|
121
119
|
|
122
120
|
### Sockets and symlinks
|
123
121
|
|
124
|
-
When using releases folders, you should set the socket path using the
|
125
|
-
|
126
|
-
|
122
|
+
When using releases folders, you should set the socket path using the shared
|
123
|
+
folder path (ex. `/srv/projet/shared/tmp/puma.sock`), not the release folder
|
124
|
+
path (`/srv/projet/releases/1234/tmp/puma.sock`).
|
127
125
|
|
128
126
|
Puma will detect the release path socket as different than the one provided by
|
129
|
-
systemd and attempt to bind it again, resulting in the exception
|
130
|
-
|
127
|
+
systemd and attempt to bind it again, resulting in the exception `There is
|
128
|
+
already a server bound to:`.
|
131
129
|
|
132
130
|
### Binding
|
133
131
|
|
134
|
-
By default you need to configure
|
132
|
+
By default, you need to configure Puma to have binds matching with all
|
135
133
|
ListenStream statements. Any mismatched systemd ListenStreams will be closed by
|
136
|
-
|
134
|
+
Puma.
|
137
135
|
|
138
136
|
To automatically bind to all activated sockets, the option
|
139
137
|
`--bind-to-activated-sockets` can be used. This matches the config DSL
|
140
|
-
`bind_to_activated_sockets` statement. This will cause
|
138
|
+
`bind_to_activated_sockets` statement. This will cause Puma to create a bind
|
141
139
|
automatically for any activated socket. When systemd socket activation is not
|
142
140
|
enabled, this option does nothing.
|
143
141
|
|
@@ -146,8 +144,8 @@ binds that's not socket activated.
|
|
146
144
|
|
147
145
|
## Usage
|
148
146
|
|
149
|
-
Without socket activation, use `systemctl` as root (e
|
150
|
-
|
147
|
+
Without socket activation, use `systemctl` as root (i.e., via `sudo`) as with
|
148
|
+
other system services:
|
151
149
|
|
152
150
|
~~~~ sh
|
153
151
|
# After installing or making changes to puma.service
|
@@ -156,35 +154,35 @@ systemctl daemon-reload
|
|
156
154
|
# Enable so it starts on boot
|
157
155
|
systemctl enable puma.service
|
158
156
|
|
159
|
-
# Initial
|
157
|
+
# Initial startup.
|
160
158
|
systemctl start puma.service
|
161
159
|
|
162
160
|
# Check status
|
163
161
|
systemctl status puma.service
|
164
162
|
|
165
|
-
# A normal restart. Warning:
|
163
|
+
# A normal restart. Warning: listener's sockets will be closed
|
166
164
|
# while a new puma process initializes.
|
167
165
|
systemctl restart puma.service
|
168
166
|
~~~~
|
169
167
|
|
170
|
-
With socket activation, several but not all of these commands should
|
171
|
-
|
168
|
+
With socket activation, several but not all of these commands should be run for
|
169
|
+
both socket and service:
|
172
170
|
|
173
171
|
~~~~ sh
|
174
172
|
# After installing or making changes to either puma.socket or
|
175
173
|
# puma.service.
|
176
174
|
systemctl daemon-reload
|
177
175
|
|
178
|
-
# Enable both socket and service so they start on boot. Alternatively
|
179
|
-
# you could leave puma.service disabled and systemd will start it on
|
180
|
-
# first use (with startup lag on first request)
|
176
|
+
# Enable both socket and service, so they start on boot. Alternatively
|
177
|
+
# you could leave puma.service disabled, and systemd will start it on
|
178
|
+
# the first use (with startup lag on the first request)
|
181
179
|
systemctl enable puma.socket puma.service
|
182
180
|
|
183
|
-
# Initial
|
181
|
+
# Initial startup. The Requires directive (see above) ensures the
|
184
182
|
# socket is started before the service.
|
185
183
|
systemctl start puma.socket puma.service
|
186
184
|
|
187
|
-
# Check status of both socket and service.
|
185
|
+
# Check the status of both socket and service.
|
188
186
|
systemctl status puma.socket puma.service
|
189
187
|
|
190
188
|
# A "hot" restart, with systemd keeping puma.socket listening and
|
@@ -197,8 +195,8 @@ systemctl restart puma.service
|
|
197
195
|
systemctl restart puma.socket puma.service
|
198
196
|
~~~~
|
199
197
|
|
200
|
-
Here is sample output from `systemctl status` with both service and
|
201
|
-
|
198
|
+
Here is sample output from `systemctl status` with both service and socket
|
199
|
+
running:
|
202
200
|
|
203
201
|
~~~~
|
204
202
|
● puma.socket - Puma HTTP Server Accept Sockets
|
@@ -231,14 +229,12 @@ Apr 07 08:40:19 hx puma[28320]: Use Ctrl-C to stop
|
|
231
229
|
|
232
230
|
### capistrano3-puma
|
233
231
|
|
234
|
-
By default,
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
also that the configured `User` should likely be the same as the
|
241
|
-
capistrano3-puma `:puma_user` option.
|
232
|
+
By default, [capistrano3-puma](https://github.com/seuros/capistrano-puma) uses
|
233
|
+
`pumactl` for deployment restarts outside of systemd. To learn the exact
|
234
|
+
commands that this tool would use for `ExecStart` and `ExecStop`, use the
|
235
|
+
following `cap` commands in dry-run mode, and update from the above forking
|
236
|
+
service configuration accordingly. Note also that the configured `User` should
|
237
|
+
likely be the same as the capistrano3-puma `:puma_user` option.
|
242
238
|
|
243
239
|
~~~~ sh
|
244
240
|
stage=production # or different stage, as needed
|
@@ -426,10 +426,13 @@ st18:
|
|
426
426
|
case 18:
|
427
427
|
#line 428 "ext/puma_http11/http11_parser.c"
|
428
428
|
switch( (*p) ) {
|
429
|
+
case 9: goto tr25;
|
429
430
|
case 13: goto tr26;
|
430
431
|
case 32: goto tr27;
|
431
432
|
}
|
432
|
-
|
433
|
+
if ( 33 <= (*p) && (*p) <= 126 )
|
434
|
+
goto tr25;
|
435
|
+
goto st0;
|
433
436
|
tr25:
|
434
437
|
#line 46 "ext/puma_http11/http11_parser.rl"
|
435
438
|
{ MARK(mark, p); }
|
@@ -438,10 +441,14 @@ st19:
|
|
438
441
|
if ( ++p == pe )
|
439
442
|
goto _test_eof19;
|
440
443
|
case 19:
|
441
|
-
#line
|
442
|
-
|
443
|
-
goto
|
444
|
-
|
444
|
+
#line 445 "ext/puma_http11/http11_parser.c"
|
445
|
+
switch( (*p) ) {
|
446
|
+
case 9: goto st19;
|
447
|
+
case 13: goto tr29;
|
448
|
+
}
|
449
|
+
if ( 32 <= (*p) && (*p) <= 126 )
|
450
|
+
goto st19;
|
451
|
+
goto st0;
|
445
452
|
tr9:
|
446
453
|
#line 53 "ext/puma_http11/http11_parser.rl"
|
447
454
|
{
|
@@ -484,7 +491,7 @@ st20:
|
|
484
491
|
if ( ++p == pe )
|
485
492
|
goto _test_eof20;
|
486
493
|
case 20:
|
487
|
-
#line
|
494
|
+
#line 495 "ext/puma_http11/http11_parser.c"
|
488
495
|
switch( (*p) ) {
|
489
496
|
case 32: goto tr31;
|
490
497
|
case 60: goto st0;
|
@@ -505,7 +512,7 @@ st21:
|
|
505
512
|
if ( ++p == pe )
|
506
513
|
goto _test_eof21;
|
507
514
|
case 21:
|
508
|
-
#line
|
515
|
+
#line 516 "ext/puma_http11/http11_parser.c"
|
509
516
|
switch( (*p) ) {
|
510
517
|
case 32: goto tr33;
|
511
518
|
case 60: goto st0;
|
@@ -526,7 +533,7 @@ st22:
|
|
526
533
|
if ( ++p == pe )
|
527
534
|
goto _test_eof22;
|
528
535
|
case 22:
|
529
|
-
#line
|
536
|
+
#line 537 "ext/puma_http11/http11_parser.c"
|
530
537
|
switch( (*p) ) {
|
531
538
|
case 43: goto st22;
|
532
539
|
case 58: goto st23;
|
@@ -551,7 +558,7 @@ st23:
|
|
551
558
|
if ( ++p == pe )
|
552
559
|
goto _test_eof23;
|
553
560
|
case 23:
|
554
|
-
#line
|
561
|
+
#line 562 "ext/puma_http11/http11_parser.c"
|
555
562
|
switch( (*p) ) {
|
556
563
|
case 32: goto tr8;
|
557
564
|
case 34: goto st0;
|
@@ -571,7 +578,7 @@ st24:
|
|
571
578
|
if ( ++p == pe )
|
572
579
|
goto _test_eof24;
|
573
580
|
case 24:
|
574
|
-
#line
|
581
|
+
#line 582 "ext/puma_http11/http11_parser.c"
|
575
582
|
switch( (*p) ) {
|
576
583
|
case 32: goto tr37;
|
577
584
|
case 34: goto st0;
|
@@ -594,7 +601,7 @@ st25:
|
|
594
601
|
if ( ++p == pe )
|
595
602
|
goto _test_eof25;
|
596
603
|
case 25:
|
597
|
-
#line
|
604
|
+
#line 605 "ext/puma_http11/http11_parser.c"
|
598
605
|
switch( (*p) ) {
|
599
606
|
case 32: goto tr41;
|
600
607
|
case 34: goto st0;
|
@@ -614,7 +621,7 @@ st26:
|
|
614
621
|
if ( ++p == pe )
|
615
622
|
goto _test_eof26;
|
616
623
|
case 26:
|
617
|
-
#line
|
624
|
+
#line 625 "ext/puma_http11/http11_parser.c"
|
618
625
|
switch( (*p) ) {
|
619
626
|
case 32: goto tr44;
|
620
627
|
case 34: goto st0;
|
@@ -43,7 +43,7 @@
|
|
43
43
|
|
44
44
|
field_name = ( token -- ":" )+ >start_field $snake_upcase_field %write_field;
|
45
45
|
|
46
|
-
field_value =
|
46
|
+
field_value = ( print | "\t" )* >start_value %write_value;
|
47
47
|
|
48
48
|
message_header = field_name ":" " "* field_value :> CRLF;
|
49
49
|
|
@@ -34,9 +34,9 @@ private static short[] init__puma_parser_key_offsets_0()
|
|
34
34
|
{
|
35
35
|
return new short [] {
|
36
36
|
0, 0, 8, 17, 27, 29, 30, 31, 32, 33, 34, 36,
|
37
|
-
39, 41, 44, 45, 61, 62, 78,
|
38
|
-
|
39
|
-
|
37
|
+
39, 41, 44, 45, 61, 62, 78, 83, 87, 95, 103, 113,
|
38
|
+
121, 130, 138, 146, 155, 164, 173, 182, 191, 200, 209, 218,
|
39
|
+
227, 236, 245, 254, 263, 272, 281, 290, 299, 308, 309
|
40
40
|
};
|
41
41
|
}
|
42
42
|
|
@@ -52,14 +52,13 @@ private static char[] init__puma_parser_trans_keys_0()
|
|
52
52
|
46, 48, 57, 48, 57, 13, 48, 57, 10, 13, 33, 124,
|
53
53
|
126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94,
|
54
54
|
122, 10, 33, 58, 124, 126, 35, 39, 42, 43, 45, 46,
|
55
|
-
48, 57, 65, 90, 94, 122, 13, 32,
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90, 32,
|
55
|
+
48, 57, 65, 90, 94, 122, 9, 13, 32, 33, 126, 9,
|
56
|
+
13, 32, 126, 32, 60, 62, 127, 0, 31, 34, 35, 32,
|
57
|
+
60, 62, 127, 0, 31, 34, 35, 43, 58, 45, 46, 48,
|
58
|
+
57, 65, 90, 97, 122, 32, 34, 35, 60, 62, 127, 0,
|
59
|
+
31, 32, 34, 35, 60, 62, 63, 127, 0, 31, 32, 34,
|
60
|
+
35, 60, 62, 127, 0, 31, 32, 34, 35, 60, 62, 127,
|
61
|
+
0, 31, 32, 36, 95, 45, 46, 48, 57, 65, 90, 32,
|
63
62
|
36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95, 45,
|
64
63
|
46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48, 57,
|
65
64
|
65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90, 32,
|
@@ -71,7 +70,8 @@ private static char[] init__puma_parser_trans_keys_0()
|
|
71
70
|
65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90, 32,
|
72
71
|
36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95, 45,
|
73
72
|
46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48, 57,
|
74
|
-
65, 90, 32,
|
73
|
+
65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90, 32,
|
74
|
+
36, 95, 45, 46, 48, 57, 65, 90, 32, 0
|
75
75
|
};
|
76
76
|
}
|
77
77
|
|
@@ -82,7 +82,7 @@ private static byte[] init__puma_parser_single_lengths_0()
|
|
82
82
|
{
|
83
83
|
return new byte [] {
|
84
84
|
0, 2, 3, 4, 2, 1, 1, 1, 1, 1, 0, 1,
|
85
|
-
0, 1, 1, 4, 1, 4,
|
85
|
+
0, 1, 1, 4, 1, 4, 3, 2, 4, 4, 2, 6,
|
86
86
|
7, 6, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
87
87
|
3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 0
|
88
88
|
};
|
@@ -95,7 +95,7 @@ private static byte[] init__puma_parser_range_lengths_0()
|
|
95
95
|
{
|
96
96
|
return new byte [] {
|
97
97
|
0, 3, 3, 3, 0, 0, 0, 0, 0, 0, 1, 1,
|
98
|
-
1, 1, 0, 6, 0, 6,
|
98
|
+
1, 1, 0, 6, 0, 6, 1, 1, 2, 2, 4, 1,
|
99
99
|
1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
100
100
|
3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0
|
101
101
|
};
|
@@ -108,9 +108,9 @@ private static short[] init__puma_parser_index_offsets_0()
|
|
108
108
|
{
|
109
109
|
return new short [] {
|
110
110
|
0, 0, 6, 13, 21, 24, 26, 28, 30, 32, 34, 36,
|
111
|
-
39, 41, 44, 46, 57, 59, 70,
|
112
|
-
|
113
|
-
|
111
|
+
39, 41, 44, 46, 57, 59, 70, 75, 79, 86, 93, 100,
|
112
|
+
108, 117, 125, 133, 140, 147, 154, 161, 168, 175, 182, 189,
|
113
|
+
196, 203, 210, 217, 224, 231, 238, 245, 252, 259, 261
|
114
114
|
};
|
115
115
|
}
|
116
116
|
|
@@ -125,23 +125,23 @@ private static byte[] init__puma_parser_indicies_0()
|
|
125
125
|
10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 1,
|
126
126
|
16, 15, 1, 17, 1, 18, 17, 1, 19, 1, 20, 21,
|
127
127
|
21, 21, 21, 21, 21, 21, 21, 21, 1, 22, 1, 23,
|
128
|
-
24, 23, 23, 23, 23, 23, 23, 23, 23, 1,
|
129
|
-
|
130
|
-
1, 1, 1, 1, 33, 34, 35, 34,
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
46, 46, 46, 1, 2, 47, 47, 47,
|
135
|
-
48, 48, 48, 48, 48, 1, 2, 49,
|
136
|
-
|
137
|
-
|
138
|
-
53, 53, 53, 53, 1, 2, 54, 54,
|
139
|
-
|
140
|
-
56, 1, 2, 57, 57, 57, 57, 57,
|
141
|
-
|
142
|
-
60, 60, 60, 60, 60, 1, 2, 61,
|
143
|
-
|
144
|
-
|
128
|
+
24, 23, 23, 23, 23, 23, 23, 23, 23, 1, 25, 26,
|
129
|
+
27, 25, 1, 28, 29, 28, 1, 30, 1, 1, 1, 1,
|
130
|
+
1, 31, 32, 1, 1, 1, 1, 1, 33, 34, 35, 34,
|
131
|
+
34, 34, 34, 1, 8, 1, 9, 1, 1, 1, 1, 35,
|
132
|
+
36, 1, 38, 1, 1, 39, 1, 1, 37, 40, 1, 42,
|
133
|
+
1, 1, 1, 1, 41, 43, 1, 45, 1, 1, 1, 1,
|
134
|
+
44, 2, 46, 46, 46, 46, 46, 1, 2, 47, 47, 47,
|
135
|
+
47, 47, 1, 2, 48, 48, 48, 48, 48, 1, 2, 49,
|
136
|
+
49, 49, 49, 49, 1, 2, 50, 50, 50, 50, 50, 1,
|
137
|
+
2, 51, 51, 51, 51, 51, 1, 2, 52, 52, 52, 52,
|
138
|
+
52, 1, 2, 53, 53, 53, 53, 53, 1, 2, 54, 54,
|
139
|
+
54, 54, 54, 1, 2, 55, 55, 55, 55, 55, 1, 2,
|
140
|
+
56, 56, 56, 56, 56, 1, 2, 57, 57, 57, 57, 57,
|
141
|
+
1, 2, 58, 58, 58, 58, 58, 1, 2, 59, 59, 59,
|
142
|
+
59, 59, 1, 2, 60, 60, 60, 60, 60, 1, 2, 61,
|
143
|
+
61, 61, 61, 61, 1, 2, 62, 62, 62, 62, 62, 1,
|
144
|
+
2, 63, 63, 63, 63, 63, 1, 2, 1, 1, 0
|
145
145
|
};
|
146
146
|
}
|
147
147
|
|
data/lib/puma/client.rb
CHANGED
data/lib/puma/cluster/worker.rb
CHANGED
@@ -106,7 +106,7 @@ module Puma
|
|
106
106
|
begin
|
107
107
|
@worker_write << "b#{Process.pid}:#{index}\n"
|
108
108
|
rescue SystemCallError, IOError
|
109
|
-
|
109
|
+
Puma::Util.purge_interrupt_queue
|
110
110
|
STDERR.puts "Master seems to have exited, exiting."
|
111
111
|
return
|
112
112
|
end
|
@@ -127,7 +127,7 @@ module Puma
|
|
127
127
|
payload = %Q!#{base_payload}{ "backlog":#{b}, "running":#{r}, "pool_capacity":#{t}, "max_threads": #{m}, "requests_count": #{rc} }\n!
|
128
128
|
io << payload
|
129
129
|
rescue IOError
|
130
|
-
|
130
|
+
Puma::Util.purge_interrupt_queue
|
131
131
|
break
|
132
132
|
end
|
133
133
|
sleep Const::WORKER_CHECK_INTERVAL
|
@@ -168,16 +168,6 @@ module Puma
|
|
168
168
|
@launcher.config.run_hooks :after_worker_fork, idx, @launcher.events
|
169
169
|
pid
|
170
170
|
end
|
171
|
-
|
172
|
-
def wakeup!
|
173
|
-
return unless @wakeup
|
174
|
-
|
175
|
-
begin
|
176
|
-
@wakeup.write "!" unless @wakeup.closed?
|
177
|
-
rescue SystemCallError, IOError
|
178
|
-
Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue
|
179
|
-
end
|
180
|
-
end
|
181
171
|
end
|
182
172
|
end
|
183
173
|
end
|
data/lib/puma/cluster.rb
CHANGED
@@ -164,16 +164,6 @@ module Puma
|
|
164
164
|
].compact.min
|
165
165
|
end
|
166
166
|
|
167
|
-
def wakeup!
|
168
|
-
return unless @wakeup
|
169
|
-
|
170
|
-
begin
|
171
|
-
@wakeup.write "!" unless @wakeup.closed?
|
172
|
-
rescue SystemCallError, IOError
|
173
|
-
Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
167
|
def worker(index, master)
|
178
168
|
@workers = []
|
179
169
|
|
data/lib/puma/configuration.rb
CHANGED
@@ -200,7 +200,7 @@ module Puma
|
|
200
200
|
:worker_shutdown_timeout => DefaultWorkerShutdownTimeout,
|
201
201
|
:remote_address => :socket,
|
202
202
|
:tag => method(:infer_tag),
|
203
|
-
:environment => -> { ENV['RACK_ENV'] || ENV['RAILS_ENV'] ||
|
203
|
+
:environment => -> { ENV['APP_ENV'] || ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development' },
|
204
204
|
:rackup => DefaultRackup,
|
205
205
|
:logger => STDOUT,
|
206
206
|
:persistent_timeout => Const::PERSISTENT_TIMEOUT,
|
data/lib/puma/const.rb
CHANGED
@@ -100,7 +100,7 @@ module Puma
|
|
100
100
|
# too taxing on performance.
|
101
101
|
module Const
|
102
102
|
|
103
|
-
PUMA_VERSION = VERSION = "5.5.
|
103
|
+
PUMA_VERSION = VERSION = "5.5.1".freeze
|
104
104
|
CODE_NAME = "Zawgyi".freeze
|
105
105
|
|
106
106
|
PUMA_SERVER_STRING = ['puma', PUMA_VERSION, CODE_NAME].join(' ').freeze
|
data/lib/puma/control_cli.rb
CHANGED
data/lib/puma/minissl.rb
CHANGED
data/lib/puma/runner.rb
CHANGED
@@ -15,6 +15,16 @@ module Puma
|
|
15
15
|
@app = nil
|
16
16
|
@control = nil
|
17
17
|
@started_at = Time.now
|
18
|
+
@wakeup = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def wakeup!
|
22
|
+
return unless @wakeup
|
23
|
+
|
24
|
+
@wakeup.write "!" unless @wakeup.closed?
|
25
|
+
|
26
|
+
rescue SystemCallError, IOError
|
27
|
+
Puma::Util.purge_interrupt_queue
|
18
28
|
end
|
19
29
|
|
20
30
|
def development?
|
@@ -108,9 +118,7 @@ module Puma
|
|
108
118
|
append = @options[:redirect_append]
|
109
119
|
|
110
120
|
if stdout
|
111
|
-
|
112
|
-
raise "Cannot redirect STDOUT to #{stdout}"
|
113
|
-
end
|
121
|
+
ensure_output_directory_exists(stdout, 'STDOUT')
|
114
122
|
|
115
123
|
STDOUT.reopen stdout, (append ? "a" : "w")
|
116
124
|
STDOUT.puts "=== puma startup: #{Time.now} ==="
|
@@ -118,9 +126,7 @@ module Puma
|
|
118
126
|
end
|
119
127
|
|
120
128
|
if stderr
|
121
|
-
|
122
|
-
raise "Cannot redirect STDERR to #{stderr}"
|
123
|
-
end
|
129
|
+
ensure_output_directory_exists(stderr, 'STDERR')
|
124
130
|
|
125
131
|
STDERR.reopen stderr, (append ? "a" : "w")
|
126
132
|
STDERR.puts "=== puma startup: #{Time.now} ==="
|
@@ -159,5 +165,12 @@ module Puma
|
|
159
165
|
server.inherit_binder @launcher.binder
|
160
166
|
server
|
161
167
|
end
|
168
|
+
|
169
|
+
private
|
170
|
+
def ensure_output_directory_exists(path, io_name)
|
171
|
+
unless Dir.exist?(File.dirname(path))
|
172
|
+
raise "Cannot redirect #{io_name} to #{path}"
|
173
|
+
end
|
174
|
+
end
|
162
175
|
end
|
163
176
|
end
|
data/lib/puma/server.rb
CHANGED
@@ -146,7 +146,7 @@ module Puma
|
|
146
146
|
begin
|
147
147
|
skt.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_CORK, 1) if skt.kind_of? TCPSocket
|
148
148
|
rescue IOError, SystemCallError
|
149
|
-
|
149
|
+
Puma::Util.purge_interrupt_queue
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
@@ -155,7 +155,7 @@ module Puma
|
|
155
155
|
begin
|
156
156
|
skt.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_CORK, 0) if skt.kind_of? TCPSocket
|
157
157
|
rescue IOError, SystemCallError
|
158
|
-
|
158
|
+
Puma::Util.purge_interrupt_queue
|
159
159
|
end
|
160
160
|
end
|
161
161
|
else
|
@@ -176,7 +176,7 @@ module Puma
|
|
176
176
|
begin
|
177
177
|
tcp_info = skt.getsockopt(Socket::IPPROTO_TCP, Socket::TCP_INFO)
|
178
178
|
rescue IOError, SystemCallError
|
179
|
-
|
179
|
+
Puma::Util.purge_interrupt_queue
|
180
180
|
@precheck_closing = false
|
181
181
|
false
|
182
182
|
else
|
@@ -491,7 +491,7 @@ module Puma
|
|
491
491
|
begin
|
492
492
|
client.close if close_socket
|
493
493
|
rescue IOError, SystemCallError
|
494
|
-
|
494
|
+
Puma::Util.purge_interrupt_queue
|
495
495
|
# Already closed
|
496
496
|
rescue StandardError => e
|
497
497
|
@events.unknown_error e, nil, "Client"
|
@@ -583,11 +583,11 @@ module Puma
|
|
583
583
|
@notify << message
|
584
584
|
rescue IOError, NoMethodError, Errno::EPIPE
|
585
585
|
# The server, in another thread, is shutting down
|
586
|
-
|
586
|
+
Puma::Util.purge_interrupt_queue
|
587
587
|
rescue RuntimeError => e
|
588
588
|
# Temporary workaround for https://bugs.ruby-lang.org/issues/13239
|
589
589
|
if e.message.include?('IOError')
|
590
|
-
|
590
|
+
Puma::Util.purge_interrupt_queue
|
591
591
|
else
|
592
592
|
raise e
|
593
593
|
end
|
data/lib/puma/util.rb
CHANGED
@@ -10,6 +10,13 @@ module Puma
|
|
10
10
|
IO.pipe
|
11
11
|
end
|
12
12
|
|
13
|
+
# An instance method on Thread has been provided to address https://bugs.ruby-lang.org/issues/13632,
|
14
|
+
# which currently effects some older versions of Ruby: 2.2.7 2.2.8 2.2.9 2.2.10 2.3.4 2.4.1
|
15
|
+
# Additional context: https://github.com/puma/puma/pull/1345
|
16
|
+
def purge_interrupt_queue
|
17
|
+
Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue
|
18
|
+
end
|
19
|
+
|
13
20
|
# Unescapes a URI escaped string with +encoding+. +encoding+ will be the
|
14
21
|
# target encoding of the string returned, and it defaults to UTF-8
|
15
22
|
if defined?(::Encoding)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puma
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.5.
|
4
|
+
version: 5.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan Phoenix
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nio4r
|