puma 5.2.0-java → 5.3.2-java

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

Potentially problematic release.


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

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 18cfabde3c7db16a77cb391148c67ff674e32f0d4bdcc49c25a3b85321004b1b
4
- data.tar.gz: afea87c5cf5f105b6971e92925de6020d6562e4715ef3e8e28f972b7d457b094
3
+ metadata.gz: 12462a4a37d0a5a4d6e3406bfe4dd7f58b61a3d17c6704408956d11aaaae4f1d
4
+ data.tar.gz: dae78d98babe25b91a16d52b90dd41827048de405d0ace0a78606e03c53880e6
5
5
  SHA512:
6
- metadata.gz: aee33c61e446787e45d92d1348de7a28a657358904adc46afa691c099d66ffda26a27dd131c2904f4cc64d52fa84054394be4453f6a6072c67f59cf8bc9734c7
7
- data.tar.gz: 5baf1e4089cf503014799c3b68fc2cae1cb80ceb21195a437a8badcaf740e0866df84d1490cad597b14e4e1461b55654e20b60820b58fa19076c3ba78933ad93
6
+ metadata.gz: 71f319f6476bb37a10f1f21dc143ed738248dfaf42a21e6e9c68b0378a905d664fdf425159b7c40533f78873ffd57bbd60c211c3cabc50f692e7ef1058b06ee9
7
+ data.tar.gz: 4123267b89373e4994e6dace674113796237304009d36e7501f3a3db9149b3b3a519163f73141bf73447bf4165fc5aeaf72b15fc5432abf6904b470e917b3fd9
data/History.md CHANGED
@@ -1,3 +1,57 @@
1
+ ## 5.3.2 / 2021-05-21
2
+
3
+ * Bugfixes
4
+ * Gracefully handle Rack not accepting CLI options (#2630, #2626)
5
+ * Fix sigterm misbehavior (#2629)
6
+ * Improvements to keepalive-connection shedding (#2628)
7
+
8
+ ## 5.3.1 / 2021-05-11
9
+
10
+ * Security
11
+ * Close keepalive connections after the maximum number of fast inlined requests (#2625)
12
+
13
+ ## 5.3.0 / 2021-05-07
14
+
15
+ * Features
16
+ * Add support for Linux's abstract sockets ([#2564], [#2526])
17
+ * Add debug to worker timeout and startup ([#2559], [#2528])
18
+ * Print warning when running one-worker cluster ([#2565], [#2534])
19
+ * Don't close systemd activated socket on pumactl restart ([#2563], [#2504])
20
+
21
+ * Bugfixes
22
+ * systemd - fix event firing ([#2591], [#2572])
23
+ * Immediately unlink temporary files ([#2613])
24
+ * Improve parsing of HTTP_HOST header ([#2605], [#2584])
25
+ * Handle fatal error that has no backtrace ([#2607], [#2552])
26
+ * Fix timing out requests too early ([#2606], [#2574])
27
+ * Handle segfault in Ruby 2.6.6 on thread-locals ([#2567], [#2566])
28
+ * Server#closed_socket? - parameter may be a MiniSSL::Socket ([#2596])
29
+ * Define UNPACK_TCP_STATE_FROM_TCP_INFO in the right place ([#2588], [#2556])
30
+ * request.rb - fix chunked assembly for ascii incompatible encodings, add test ([#2585], [#2583])
31
+
32
+ * Performance
33
+ * Reset peerip only if remote_addr_header is set ([#2609])
34
+ * Reduce puma_parser struct size ([#2590])
35
+
36
+ * Refactor
37
+ * Refactor drain on shutdown ([#2600])
38
+ * Micro optimisations in `wait_for_less_busy_worker` feature ([#2579])
39
+ * Lots of test fixes
40
+
41
+ ## 5.2.2 / 2021-02-22
42
+
43
+ * Bugfixes
44
+ * Add `#flush` and `#sync` methods to `Puma::NullIO` ([#2553])
45
+ * Restore `sync=true` on `STDOUT` and `STDERR` streams ([#2557])
46
+
47
+ ## 5.2.1 / 2021-02-05
48
+
49
+ * Bugfixes
50
+ * Fix TCP cork/uncork operations to work with ssl clients ([#2550])
51
+ * Require rack/common_logger explicitly if :verbose is true ([#2547])
52
+ * MiniSSL::Socket#write - use data.byteslice(wrote..-1) ([#2543])
53
+ * Set `@env[CONTENT_LENGTH]` value as string. ([#2549])
54
+
1
55
  ## 5.2.0 / 2021-01-27
2
56
 
3
57
  * Features
@@ -166,6 +220,11 @@
166
220
  * Support parallel tests in verbose progress reporting ([#2223])
167
221
  * Refactor error handling in server accept loop ([#2239])
168
222
 
223
+ ## 4.3.8 / 2021-05-11
224
+
225
+ * Security
226
+ * Close keepalive connections after the maximum number of fast inlined requests (#2625)
227
+
169
228
  ## 4.3.7 / 2020-11-30
170
229
 
171
230
  * Bugfixes
@@ -1694,6 +1753,40 @@ be added back in a future date when a java Puma::MiniSSL is added.
1694
1753
  * Bugfixes
1695
1754
  * Your bugfix goes here <Most recent on the top, like GitHub> (#Github Number)
1696
1755
 
1756
+ [#2564]:https://github.com/puma/puma/pull/2564 "PR by @MSP-Greg, merged 2021-04-24"
1757
+ [#2526]:https://github.com/puma/puma/issues/2526 "Issue by @nerdrew, closed 2021-04-24"
1758
+ [#2559]:https://github.com/puma/puma/pull/2559 "PR by @ylecuyer, merged 2021-03-11"
1759
+ [#2528]:https://github.com/puma/puma/issues/2528 "Issue by @cjlarose, closed 2021-03-11"
1760
+ [#2565]:https://github.com/puma/puma/pull/2565 "PR by @CGA1123, merged 2021-03-09"
1761
+ [#2534]:https://github.com/puma/puma/issues/2534 "Issue by @nateberkopec, closed 2021-03-09"
1762
+ [#2563]:https://github.com/puma/puma/pull/2563 "PR by @MSP-Greg, merged 2021-03-06"
1763
+ [#2504]:https://github.com/puma/puma/issues/2504 "Issue by @fsateler, closed 2021-03-06"
1764
+ [#2591]:https://github.com/puma/puma/pull/2591 "PR by @MSP-Greg, merged 2021-05-05"
1765
+ [#2572]:https://github.com/puma/puma/issues/2572 "Issue by @josefbilendo, closed 2021-05-05"
1766
+ [#2613]:https://github.com/puma/puma/pull/2613 "PR by @smcgivern, merged 2021-04-27"
1767
+ [#2605]:https://github.com/puma/puma/pull/2605 "PR by @pascalbetz, merged 2021-04-26"
1768
+ [#2584]:https://github.com/puma/puma/issues/2584 "Issue by @kaorihinata, closed 2021-04-26"
1769
+ [#2607]:https://github.com/puma/puma/pull/2607 "PR by @calvinxiao, merged 2021-04-23"
1770
+ [#2552]:https://github.com/puma/puma/issues/2552 "Issue by @feliperaul, opened 2021-02-09"
1771
+ [#2606]:https://github.com/puma/puma/pull/2606 "PR by @wjordan, merged 2021-04-20"
1772
+ [#2574]:https://github.com/puma/puma/issues/2574 "Issue by @darkhelmet, closed 2021-04-20"
1773
+ [#2567]:https://github.com/puma/puma/pull/2567 "PR by @kddeisz, merged 2021-04-19"
1774
+ [#2566]:https://github.com/puma/puma/issues/2566 "Issue by @kddeisz, closed 2021-04-19"
1775
+ [#2596]:https://github.com/puma/puma/pull/2596 "PR by @MSP-Greg, merged 2021-04-18"
1776
+ [#2588]:https://github.com/puma/puma/pull/2588 "PR by @dentarg, merged 2021-04-02"
1777
+ [#2556]:https://github.com/puma/puma/issues/2556 "Issue by @gamecreature, closed 2021-04-02"
1778
+ [#2585]:https://github.com/puma/puma/pull/2585 "PR by @MSP-Greg, merged 2021-03-26"
1779
+ [#2583]:https://github.com/puma/puma/issues/2583 "Issue by @jboler, closed 2021-03-26"
1780
+ [#2609]:https://github.com/puma/puma/pull/2609 "PR by @calvinxiao, merged 2021-04-26"
1781
+ [#2590]:https://github.com/puma/puma/pull/2590 "PR by @calvinxiao, merged 2021-04-05"
1782
+ [#2600]:https://github.com/puma/puma/pull/2600 "PR by @wjordan, merged 2021-04-30"
1783
+ [#2579]:https://github.com/puma/puma/pull/2579 "PR by @ghiculescu, merged 2021-03-17"
1784
+ [#2553]:https://github.com/puma/puma/pull/2553 "PR by @olivierbellone, merged 2021-02-10"
1785
+ [#2557]:https://github.com/puma/puma/pull/2557 "PR by @cjlarose, merged 2021-02-22"
1786
+ [#2550]:https://github.com/puma/puma/pull/2550 "PR by @MSP-Greg, merged 2021-02-05"
1787
+ [#2547]:https://github.com/puma/puma/pull/2547 "PR by @wildmaples, merged 2021-02-03"
1788
+ [#2543]:https://github.com/puma/puma/pull/2543 "PR by @MSP-Greg, merged 2021-02-01"
1789
+ [#2549]:https://github.com/puma/puma/pull/2549 "PR by @nmb, merged 2021-02-04"
1697
1790
  [#2519]:https://github.com/puma/puma/pull/2519 "PR by @MSP-Greg, merged 2021-01-26"
1698
1791
  [#2522]:https://github.com/puma/puma/pull/2522 "PR by @jcmfernandes, merged 2021-01-12"
1699
1792
  [#2490]:https://github.com/puma/puma/pull/2490 "PR by @Bonias, merged 2020-12-07"
data/README.md CHANGED
@@ -16,7 +16,7 @@ Puma is a **simple, fast, multi-threaded, and highly concurrent HTTP 1.1 server
16
16
 
17
17
  Puma processes requests using a C-optimized Ragel extension (inherited from Mongrel) that provides fast, accurate HTTP 1.1 protocol parsing in a portable way. Puma then serves the request using a thread pool. Each request is served in a separate thread, so truly concurrent Ruby implementations (JRuby, Rubinius) will use all available CPU cores.
18
18
 
19
- Puma was designed to be the go-to server for [Rubinius](https://rubinius.com), but also works well with JRuby and MRI.
19
+ Originally designed as a server for [Rubinius](https://github.com/rubinius/rubinius), Puma also works well with Ruby (MRI) and JRuby.
20
20
 
21
21
  On MRI, there is a Global VM Lock (GVL) that ensures only one thread can run Ruby code at a time. But if you're doing a lot of blocking IO (such as HTTP calls to external APIs like Twitter), Puma still improves MRI's throughput by allowing IO waiting to be done in parallel.
22
22
 
data/docs/architecture.md CHANGED
@@ -4,34 +4,38 @@
4
4
 
5
5
  ![https://bit.ly/2iJuFky](images/puma-general-arch.png)
6
6
 
7
- Puma is a threaded web server, processing requests across a TCP or UNIX socket.
7
+ Puma is a threaded Ruby HTTP application server, processing requests across a TCP or UNIX socket.
8
8
 
9
- Workers accept connections from the socket and a thread in the worker's thread pool processes the client's request.
10
9
 
11
- Clustered mode is shown/discussed here. Single mode is analogous to having a single worker process.
10
+ Puma processes (there can be one or many) accept connections from the socket via a thread (in the [`Reactor`](../lib/puma/reactor.rb) class). The connection, once fully buffered and read, moves in to the `todo` list, where it will be picked up by a free/waiting thread in the threadpool (the [`ThreadPool`](../lib/puma/thread_pool.rb) class).
12
11
 
13
- ## Connection pipeline
12
+ Puma works in two main modes: cluster and single. In single mode, only one Puma process is booted. In cluster mode, a `master` process is booted, which prepares (and may boot) the application, and then uses the `fork()` system call to create 1 or more `child` processes. These `child` processes all listen to the same socket. The `master` process does not listen to the socket or process requests - its purpose is mostly to manage and listen for UNIX signals and possibly kill or boot `child` processes.
13
+
14
+ We sometimes call `child` processes (or Puma processes in `single` mode) _workers_, and we sometimes call the threads created by Puma's [`ThreadPool`](../lib/puma/thread_pool.rb) _worker threads_.
15
+
16
+ ## How Requests Work
14
17
 
15
18
  ![https://bit.ly/2zwzhEK](images/puma-connection-flow.png)
16
19
 
17
20
  * Upon startup, Puma listens on a TCP or UNIX socket.
18
- * The backlog of this socket is configured (with a default of 1024), determining how many established but unaccepted connections can exist concurrently.
19
- * This socket backlog is distinct from the "backlog" of work as reported by the control server stats. The latter is the number of connections in that worker's "todo" set waiting for a worker thread.
20
- * By default, a single, separate thread is used to receive HTTP requests across the socket.
21
- * When at least one worker thread is available for work, a connection is accepted and placed in this request buffer
22
- * This thread waits for entire HTTP requests to be received over the connection
23
- * The time spent waiting for the HTTP request body to be received is exposed to the Rack app as `env['puma.request_body_wait']` (milliseconds)
24
- * Once received, the connection is pushed into the "todo" set
25
- * Worker threads pop work off the "todo" set for processing
26
- * The thread processes the request via the rack application (which generates the HTTP response)
27
- * The thread writes the response to the connection
28
- * Finally, the thread become available to process another connection in the "todo" set
29
-
30
- ### Disabling `queue_requests`
21
+ * The backlog of this socket is configured (with a default of 1024). This determines the size of the queue for unaccepted connections. Generally, this setting is unimportant and will never be hit in production use. If the backlog is full, the connection will be refused by the operating system.
22
+ * This socket backlog is distinct from the `backlog` of work as reported by `Puma.stats` or the control server. The backlog as reported by Puma is the number of connections in the process' `todo` set waiting for a thread from the [`ThreadPool`](../lib/puma/thread_pool.rb).
23
+ * By default, a single, separate thread (created by the [`Reactor`](../lib/puma/reactor.rb) class) is used to read and buffer requests from the socket.
24
+ * When at least one worker thread is available for work, the reactor thread listens to the socket and accepts a request, if one is waiting.
25
+ * The reactor thread waits for the entire HTTP request to be received.
26
+ * The time spent waiting for the HTTP request body to be received is exposed to the Rack app as `env['puma.request_body_wait']` (milliseconds).
27
+ * Once fully buffered and received, the connection is pushed into the "todo" set.
28
+ * Worker threads pop work off the "todo" set for processing.
29
+ * The worker thread processes the request via `call`ing the configured Rack application. The Rack application generates the HTTP response.
30
+ * The worker thread writes the response to the connection. Note that while Puma buffers requests via a separate thread, it does not use a separate thread for responses.
31
+ * Once done, the thread become available to process another connection in the "todo" set.
32
+
33
+ ### `queue_requests`
31
34
 
32
35
  ![https://bit.ly/2zxCJ1Z](images/puma-connection-flow-no-reactor.png)
33
36
 
34
- The `queue_requests` option is `true` by default, enabling the separate thread used to buffer requests as described above.
37
+ The `queue_requests` option is `true` by default, enabling the separate reactor thread used to buffer requests as described above.
35
38
 
36
39
  If set to `false`, this buffer will not be used for connections while waiting for the request to arrive.
40
+
37
41
  In this mode, when a connection is accepted, it is added to the "todo" queue immediately, and a worker will synchronously do any waiting necessary to read the HTTP request from the socket.
data/docs/deployment.md CHANGED
@@ -16,7 +16,7 @@ Welcome back!
16
16
 
17
17
  ## Single vs Cluster mode
18
18
 
19
- Puma was originally conceived as a thread-only webserver, but grew the ability to
19
+ Puma was originally conceived as a thread-only web server, but grew the ability to
20
20
  also use processes in version 2.
21
21
 
22
22
  To run `puma` in single mode (e.g. for a development environment) you will need to
@@ -1,6 +1,6 @@
1
1
  # Puma as a service using rc.d
2
2
 
3
- Manage multilpe Puma servers as services on one box using FreeBSD's rc.d service.
3
+ Manage multiple Puma servers as services on one box using FreeBSD's rc.d service.
4
4
 
5
5
  ## Dependencies
6
6
 
data/docs/kubernetes.md CHANGED
@@ -61,6 +61,6 @@ For some high-throughput systems, it is possible that some HTTP requests will re
61
61
 
62
62
  There is a subtle race condition between step 2 and 3: The replication controller does not synchronously remove the pod from the Services AND THEN call the pre-stop hook of the pod, but rather it asynchronously sends "remove this pod from your endpoints" requests to the Services and then immediately proceeds to invoke the pods' pre-stop hook. If the Service controller (typically something like nginx or haproxy) receives this request handles this request "too" late (due to internal lag or network latency between the replication and Service controllers) then it is possible that the Service controller will send one or more requests to a Puma process which has already shut down its listening socket. These requests will then fail with 5XX error codes.
63
63
 
64
- The way Kubernetes works this way, rather than handling step 2 synchronously, is due to the CAP theorem: in a distributed system there is no way to guarantuee that any message will arrive promptly. In particular, waiting for all Service controllers to report back might get stuck for an indefinite time if one of them has already been terminated or if there has been a net split. A way to work around this is to add a sleep to the pre-stop hook of the same time as the `terminationGracePeriodSeconds` time. This will allow the Puma process to keep serving new requests during the entire grace period, although it will no longer receive new requests after all Service controllers have propagated the removal of the pod from their endpoint lists. Then, after `terminationGracePeriodSeconds`, the pod receives `SIGKILL` and closes down. If your process can't handle SIGKILL properly, for example because it needs to release locks in different services, you can also sleep for a shorter period (and/or increase `terminationGracePeriodSeconds`) as long as the time slept is longer than the time that your Service controllers take to propagate the pod removal. The downside of this workaround is that all pods will take at minimum the amount of time slept to shut down and this will increase the time required for your rolling deploy.
64
+ The way Kubernetes works this way, rather than handling step 2 synchronously, is due to the CAP theorem: in a distributed system there is no way to guarantee that any message will arrive promptly. In particular, waiting for all Service controllers to report back might get stuck for an indefinite time if one of them has already been terminated or if there has been a net split. A way to work around this is to add a sleep to the pre-stop hook of the same time as the `terminationGracePeriodSeconds` time. This will allow the Puma process to keep serving new requests during the entire grace period, although it will no longer receive new requests after all Service controllers have propagated the removal of the pod from their endpoint lists. Then, after `terminationGracePeriodSeconds`, the pod receives `SIGKILL` and closes down. If your process can't handle SIGKILL properly, for example because it needs to release locks in different services, you can also sleep for a shorter period (and/or increase `terminationGracePeriodSeconds`) as long as the time slept is longer than the time that your Service controllers take to propagate the pod removal. The downside of this workaround is that all pods will take at minimum the amount of time slept to shut down and this will increase the time required for your rolling deploy.
65
65
 
66
66
  More discussions and links to relevant articles can be found in https://github.com/puma/puma/issues/2343.
data/docs/plugins.md CHANGED
@@ -34,5 +34,5 @@ functionality to augment puma.
34
34
  `config` runs when the server is being configured and is passed a `Puma::DSL`
35
35
  object that can be used to add additional configuration.
36
36
 
37
- Any public methods in `Puma::Plugin` are the public API that any plugin may
37
+ Any public methods in [`Puma::Plugin`](../lib/puma/plugin.rb) are the public API that any plugin may
38
38
  use.
@@ -0,0 +1,29 @@
1
+ # Running Puma in Rails Development Mode
2
+
3
+ ## "Loopback requests"
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 is completed. 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
+
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
+
9
+ ### Solutions
10
+
11
+
12
+ #### 1. Bypass Rails' load interlock with `.permit_concurrent_loads`
13
+
14
+ 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
+
16
+ ###### Example
17
+
18
+ ```ruby
19
+ response = ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
20
+ # Your HTTP request code here. For example:
21
+ Faraday.post url, data: 'foo'
22
+ end
23
+
24
+ do_something_with response
25
+ ```
26
+
27
+ #### 2. Use multiple processes on Puma
28
+
29
+ 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
@@ -45,7 +45,7 @@ Any of the following will cause a Puma server to perform a phased restart:
45
45
  ### Supported configurations
46
46
 
47
47
  * Works in cluster mode only
48
- * To support upgrading the application that Puma is serving, ensure `prune_bundler` is enabled and that `preload_app` is disabled (it is disabled by default).
48
+ * To support upgrading the application that Puma is serving, ensure `prune_bundler` is enabled and that `preload_app!` is disabled
49
49
  * Supported on all platforms where cluster mode is supported
50
50
 
51
51
  ### Client experience
data/docs/stats.md CHANGED
@@ -53,7 +53,7 @@ end
53
53
 
54
54
  ### single mode and individual workers in cluster mode
55
55
 
56
- When Puma is run in single mode, these stats ar available at the top level. When Puma is run in cluster mode, these stats are available within the `worker_status` array in a hash labeled `last_status`, in an array of hashes, one hash for each worker.
56
+ When Puma is run in single mode, these stats are available at the top level. When Puma is run in cluster mode, these stats are available within the `worker_status` array in a hash labeled `last_status`, in an array of hashes, one hash for 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
data/docs/systemd.md CHANGED
@@ -8,7 +8,7 @@ useful features for running Puma in production.
8
8
  ## Service Configuration
9
9
 
10
10
  Below is a sample puma.service configuration file for systemd, which
11
- can be copied or symlinked to /etc/systemd/system/puma.service, or if
11
+ can be copied or symlinked to `/etc/systemd/system/puma.service`, or if
12
12
  desired, using an application or instance specific name.
13
13
 
14
14
  Note that this uses the systemd preferred "simple" type where the
@@ -29,8 +29,8 @@ typedef void (*field_cb)(struct puma_parser* hp,
29
29
 
30
30
  typedef struct puma_parser {
31
31
  int cs;
32
- size_t body_start;
33
32
  int content_len;
33
+ size_t body_start;
34
34
  size_t nread;
35
35
  size_t mark;
36
36
  size_t field_start;
data/lib/puma.rb CHANGED
@@ -19,6 +19,40 @@ module Puma
19
19
  autoload :Server, 'puma/server'
20
20
  autoload :Launcher, 'puma/launcher'
21
21
 
22
+ # at present, MiniSSL::Engine is only defined in extension code (puma_http11),
23
+ # not in minissl.rb
24
+ HAS_SSL = const_defined?(:MiniSSL, false) && MiniSSL.const_defined?(:Engine, false)
25
+
26
+ HAS_UNIX_SOCKET = Object.const_defined? :UNIXSocket
27
+
28
+ if HAS_SSL
29
+ require 'puma/minissl'
30
+ else
31
+ module MiniSSL
32
+ # this class is defined so that it exists when Puma is compiled
33
+ # without ssl support, as Server and Reactor use it in rescue statements.
34
+ class SSLError < StandardError ; end
35
+ end
36
+ end
37
+
38
+ def self.ssl?
39
+ HAS_SSL
40
+ end
41
+
42
+ def self.abstract_unix_socket?
43
+ @abstract_unix ||=
44
+ if HAS_UNIX_SOCKET
45
+ begin
46
+ ::UNIXServer.new("\0puma.temp.unix").close
47
+ true
48
+ rescue ArgumentError # darwin
49
+ false
50
+ end
51
+ else
52
+ false
53
+ end
54
+ end
55
+
22
56
  # @!attribute [rw] stats_object=
23
57
  def self.stats_object=(val)
24
58
  @get_stats = val
@@ -40,12 +74,4 @@ module Puma
40
74
  return unless Thread.current.respond_to?(:name=)
41
75
  Thread.current.name = "puma #{name}"
42
76
  end
43
-
44
- unless HAS_SSL
45
- module MiniSSL
46
- # this class is defined so that it exists when Puma is compiled
47
- # without ssl support, as Server and Reactor use it in rescue statements.
48
- class SSLError < StandardError ; end
49
- end
50
- end
51
77
  end
data/lib/puma/binder.rb CHANGED
@@ -13,7 +13,7 @@ module Puma
13
13
  require 'puma/minissl'
14
14
  require 'puma/minissl/context_builder'
15
15
 
16
- # Odd bug in 'pure Ruby' nio4r verion 2.5.2, which installs with Ruby 2.3.
16
+ # Odd bug in 'pure Ruby' nio4r version 2.5.2, which installs with Ruby 2.3.
17
17
  # NIO doesn't create any OpenSSL objects, but it rescues an OpenSSL error.
18
18
  # The bug was that it did not require openssl.
19
19
  # @todo remove when Ruby 2.3 support is dropped
@@ -163,7 +163,7 @@ module Puma
163
163
  ios_len = @ios.length
164
164
  params = Util.parse_query uri.query
165
165
 
166
- opt = params.key?('low_latency')
166
+ opt = params.key?('low_latency') && params['low_latency'] != 'false'
167
167
  bak = params.fetch('backlog', 1024).to_i
168
168
 
169
169
  io = add_tcp_listener uri.host, uri.port, opt, bak
@@ -177,11 +177,19 @@ module Puma
177
177
  @listeners << [str, io] if io
178
178
  when "unix"
179
179
  path = "#{uri.host}#{uri.path}".gsub("%20", " ")
180
+ abstract = false
181
+ if str.start_with? 'unix://@'
182
+ raise "OS does not support abstract UNIXSockets" unless Puma.abstract_unix_socket?
183
+ abstract = true
184
+ path = "@#{path}"
185
+ end
180
186
 
181
187
  if fd = @inherited_fds.delete(str)
188
+ @unix_paths << path unless abstract
182
189
  io = inherit_unix_listener path, fd
183
190
  logger.log "* Inherited #{str}"
184
191
  elsif sock = @activated_sockets.delete([ :unix, path ])
192
+ @unix_paths << path unless abstract || File.exist?(path)
185
193
  io = inherit_unix_listener path, sock
186
194
  logger.log "* Activated #{str}"
187
195
  else
@@ -205,6 +213,7 @@ module Puma
205
213
  end
206
214
  end
207
215
 
216
+ @unix_paths << path unless abstract || File.exist?(path)
208
217
  io = add_unix_listener path, umask, mode, backlog
209
218
  logger.log "* #{log_msg} on #{str}"
210
219
  end
@@ -258,14 +267,18 @@ module Puma
258
267
  end
259
268
 
260
269
  # Also close any unused activated sockets
261
- @activated_sockets.each do |key, sock|
262
- logger.log "* Closing unused activated socket: #{key.join ':'}"
263
- begin
264
- sock.close
265
- rescue SystemCallError
270
+ unless @activated_sockets.empty?
271
+ fds = @ios.map(&:to_i)
272
+ @activated_sockets.each do |key, sock|
273
+ next if fds.include? sock.to_i
274
+ logger.log "* Closing unused activated socket: #{key.first}://#{key[1..-1].join ':'}"
275
+ begin
276
+ sock.close
277
+ rescue SystemCallError
278
+ end
279
+ # We have to unlink a unix socket path that's not being used
280
+ File.unlink key[1] if key.first == :unix
266
281
  end
267
- # We have to unlink a unix socket path that's not being used
268
- File.unlink key[1] if key[0] == :unix
269
282
  end
270
283
  end
271
284
 
@@ -351,8 +364,6 @@ module Puma
351
364
  # Tell the server to listen on +path+ as a UNIX domain socket.
352
365
  #
353
366
  def add_unix_listener(path, umask=nil, mode=nil, backlog=1024)
354
- @unix_paths << path unless File.exist? path
355
-
356
367
  # Let anyone connect by default
357
368
  umask ||= 0
358
369
 
@@ -369,8 +380,7 @@ module Puma
369
380
  raise "There is already a server bound to: #{path}"
370
381
  end
371
382
  end
372
-
373
- s = UNIXServer.new(path)
383
+ s = UNIXServer.new path.sub(/\A@/, "\0") # check for abstract UNIXSocket
374
384
  s.listen backlog
375
385
  @ios << s
376
386
  ensure
@@ -389,8 +399,6 @@ module Puma
389
399
  end
390
400
 
391
401
  def inherit_unix_listener(path, fd)
392
- @unix_paths << path unless File.exist? path
393
-
394
402
  s = fd.kind_of?(::TCPServer) ? fd : ::UNIXServer.for_fd(fd)
395
403
 
396
404
  @ios << s
@@ -403,24 +411,24 @@ module Puma
403
411
  end
404
412
 
405
413
  def close_listeners
406
- listeners.each do |l, io|
407
- io.close unless io.closed? # Ruby 2.2 issue
408
- uri = URI.parse(l)
414
+ @listeners.each do |l, io|
415
+ io.close unless io.closed?
416
+ uri = URI.parse l
409
417
  next unless uri.scheme == 'unix'
410
418
  unix_path = "#{uri.host}#{uri.path}"
411
- File.unlink unix_path if unix_paths.include? unix_path
419
+ File.unlink unix_path if @unix_paths.include?(unix_path) && File.exist?(unix_path)
412
420
  end
413
421
  end
414
422
 
415
423
  def redirects_for_restart
416
- redirects = listeners.map { |a| [a[1].to_i, a[1].to_i] }.to_h
424
+ redirects = @listeners.map { |a| [a[1].to_i, a[1].to_i] }.to_h
417
425
  redirects[:close_others] = true
418
426
  redirects
419
427
  end
420
428
 
421
429
  # @version 5.0.0
422
430
  def redirects_for_restart_env
423
- listeners.each_with_object({}).with_index do |(listen, memo), i|
431
+ @listeners.each_with_object({}).with_index do |(listen, memo), i|
424
432
  memo["PUMA_INHERIT_#{i}"] = "#{listen[1].to_i}:#{listen[0]}"
425
433
  end
426
434
  end