puma 4.3.12 → 5.0.0
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.
- checksums.yaml +4 -4
- data/History.md +79 -32
- data/LICENSE +23 -20
- data/README.md +26 -13
- data/bin/puma-wild +0 -0
- data/docs/architecture.md +3 -3
- data/docs/deployment.md +9 -3
- data/docs/fork_worker.md +31 -0
- data/docs/images/puma-connection-flow-no-reactor.png +0 -0
- data/docs/images/puma-connection-flow.png +0 -0
- data/docs/images/puma-general-arch.png +0 -0
- data/docs/jungle/README.md +13 -0
- data/{tools → docs}/jungle/rc.d/README.md +0 -0
- data/{tools → docs}/jungle/rc.d/puma.conf +0 -0
- data/{tools → docs}/jungle/upstart/README.md +0 -0
- data/{tools → docs}/jungle/upstart/puma-manager.conf +0 -0
- data/{tools → docs}/jungle/upstart/puma.conf +0 -0
- data/docs/nginx.md +0 -0
- data/docs/plugins.md +0 -0
- data/docs/restart.md +0 -0
- data/docs/signals.md +7 -6
- data/docs/systemd.md +1 -63
- data/ext/puma_http11/PumaHttp11Service.java +2 -4
- data/ext/puma_http11/ext_help.h +0 -0
- data/ext/puma_http11/extconf.rb +3 -10
- data/ext/puma_http11/http11_parser.c +10 -23
- data/ext/puma_http11/http11_parser.h +0 -0
- data/ext/puma_http11/http11_parser.java.rl +0 -0
- data/ext/puma_http11/http11_parser.rl +0 -0
- data/ext/puma_http11/http11_parser_common.rl +1 -1
- data/ext/puma_http11/mini_ssl.c +62 -84
- data/ext/puma_http11/no_ssl/PumaHttp11Service.java +15 -0
- data/ext/puma_http11/org/jruby/puma/Http11.java +3 -3
- data/ext/puma_http11/org/jruby/puma/Http11Parser.java +46 -48
- data/ext/puma_http11/org/jruby/puma/MiniSSL.java +77 -18
- data/ext/puma_http11/puma_http11.c +6 -38
- data/lib/puma/accept_nonblock.rb +0 -0
- data/lib/puma/app/status.rb +14 -1
- data/lib/puma/binder.rb +88 -68
- data/lib/puma/cli.rb +7 -15
- data/lib/puma/client.rb +49 -59
- data/lib/puma/cluster.rb +191 -74
- data/lib/puma/commonlogger.rb +2 -2
- data/lib/puma/configuration.rb +31 -42
- data/lib/puma/const.rb +6 -8
- data/lib/puma/control_cli.rb +29 -17
- data/lib/puma/detect.rb +17 -0
- data/lib/puma/dsl.rb +144 -70
- data/lib/puma/error_logger.rb +97 -0
- data/lib/puma/events.rb +35 -31
- data/lib/puma/io_buffer.rb +9 -2
- data/lib/puma/jruby_restart.rb +0 -58
- data/lib/puma/launcher.rb +49 -31
- data/lib/puma/minissl/context_builder.rb +0 -3
- data/lib/puma/minissl.rb +60 -18
- data/lib/puma/null_io.rb +1 -1
- data/lib/puma/plugin/tmp_restart.rb +0 -0
- data/lib/puma/plugin.rb +1 -10
- data/lib/puma/rack/builder.rb +0 -4
- data/lib/puma/rack/urlmap.rb +0 -0
- data/lib/puma/rack_default.rb +0 -0
- data/lib/puma/reactor.rb +9 -4
- data/lib/puma/runner.rb +8 -36
- data/lib/puma/server.rb +122 -215
- data/lib/puma/single.rb +7 -64
- data/lib/puma/state_file.rb +6 -3
- data/lib/puma/thread_pool.rb +94 -49
- data/lib/puma/util.rb +0 -0
- data/lib/puma.rb +17 -0
- data/lib/rack/handler/puma.rb +1 -3
- data/tools/{docker/Dockerfile → Dockerfile} +0 -0
- data/tools/trickletest.rb +0 -0
- metadata +18 -20
- data/docs/tcp_mode.md +0 -96
- data/ext/puma_http11/io_buffer.c +0 -155
- data/ext/puma_http11/org/jruby/puma/IOBuffer.java +0 -72
- data/lib/puma/tcp_logger.rb +0 -41
- data/tools/jungle/README.md +0 -19
- data/tools/jungle/init.d/README.md +0 -61
- data/tools/jungle/init.d/puma +0 -421
- data/tools/jungle/init.d/run-puma +0 -18
- /data/{tools → docs}/jungle/rc.d/puma +0 -0
data/lib/puma/configuration.rb
CHANGED
|
@@ -54,9 +54,7 @@ module Puma
|
|
|
54
54
|
attr_reader :user_options, :file_options, :default_options
|
|
55
55
|
|
|
56
56
|
def [](key)
|
|
57
|
-
|
|
58
|
-
return file_options[key] if file_options.key?(key)
|
|
59
|
-
return default_options[key] if default_options.key?(key)
|
|
57
|
+
fetch(key)
|
|
60
58
|
end
|
|
61
59
|
|
|
62
60
|
def []=(key, value)
|
|
@@ -64,7 +62,11 @@ module Puma
|
|
|
64
62
|
end
|
|
65
63
|
|
|
66
64
|
def fetch(key, default_value = nil)
|
|
67
|
-
|
|
65
|
+
return user_options[key] if user_options.key?(key)
|
|
66
|
+
return file_options[key] if file_options.key?(key)
|
|
67
|
+
return default_options[key] if default_options.key?(key)
|
|
68
|
+
|
|
69
|
+
default_value
|
|
68
70
|
end
|
|
69
71
|
|
|
70
72
|
def all_of(key)
|
|
@@ -106,7 +108,7 @@ module Puma
|
|
|
106
108
|
#
|
|
107
109
|
# It also handles loading plugins.
|
|
108
110
|
#
|
|
109
|
-
# > Note: `:port` and `:host` are not valid keys. By
|
|
111
|
+
# > Note: `:port` and `:host` are not valid keys. By the time they make it to the
|
|
110
112
|
# configuration options they are expected to be incorporated into a `:binds` key.
|
|
111
113
|
# Under the hood the DSL maps `port` and `host` calls to `:binds`
|
|
112
114
|
#
|
|
@@ -137,6 +139,10 @@ module Puma
|
|
|
137
139
|
@file_dsl = DSL.new(@options.file_options, self)
|
|
138
140
|
@default_dsl = DSL.new(@options.default_options, self)
|
|
139
141
|
|
|
142
|
+
if !@options[:prune_bundler]
|
|
143
|
+
default_options[:preload_app] = (@options[:workers] > 1) && Puma.forkable?
|
|
144
|
+
end
|
|
145
|
+
|
|
140
146
|
if block
|
|
141
147
|
configure(&block)
|
|
142
148
|
end
|
|
@@ -167,22 +173,26 @@ module Puma
|
|
|
167
173
|
self
|
|
168
174
|
end
|
|
169
175
|
|
|
176
|
+
# @version 5.0.0
|
|
177
|
+
def default_max_threads
|
|
178
|
+
Puma.mri? ? 5 : 16
|
|
179
|
+
end
|
|
180
|
+
|
|
170
181
|
def puma_default_options
|
|
171
182
|
{
|
|
172
|
-
:min_threads => 0,
|
|
173
|
-
:max_threads =>
|
|
183
|
+
:min_threads => Integer(ENV['PUMA_MIN_THREADS'] || ENV['MIN_THREADS'] || 0),
|
|
184
|
+
:max_threads => Integer(ENV['PUMA_MAX_THREADS'] || ENV['MAX_THREADS'] || default_max_threads),
|
|
174
185
|
:log_requests => false,
|
|
175
186
|
:debug => false,
|
|
176
187
|
:binds => ["tcp://#{DefaultTCPHost}:#{DefaultTCPPort}"],
|
|
177
|
-
:workers => 0,
|
|
178
|
-
:daemon => false,
|
|
188
|
+
:workers => Integer(ENV['WEB_CONCURRENCY'] || 0),
|
|
179
189
|
:mode => :http,
|
|
180
190
|
:worker_timeout => DefaultWorkerTimeout,
|
|
181
191
|
:worker_boot_timeout => DefaultWorkerTimeout,
|
|
182
192
|
:worker_shutdown_timeout => DefaultWorkerShutdownTimeout,
|
|
183
193
|
:remote_address => :socket,
|
|
184
194
|
:tag => method(:infer_tag),
|
|
185
|
-
:environment => -> { ENV['RACK_ENV'] || "development" },
|
|
195
|
+
:environment => -> { ENV['RACK_ENV'] || ENV['RAILS_ENV'] || "development" },
|
|
186
196
|
:rackup => DefaultRackup,
|
|
187
197
|
:logger => STDOUT,
|
|
188
198
|
:persistent_timeout => Const::PERSISTENT_TIMEOUT,
|
|
@@ -245,14 +255,6 @@ module Puma
|
|
|
245
255
|
def app
|
|
246
256
|
found = options[:app] || load_rackup
|
|
247
257
|
|
|
248
|
-
if @options[:mode] == :tcp
|
|
249
|
-
require 'puma/tcp_logger'
|
|
250
|
-
|
|
251
|
-
logger = @options[:logger]
|
|
252
|
-
quiet = !@options[:log_requests]
|
|
253
|
-
return TCPLogger.new(logger, found, quiet)
|
|
254
|
-
end
|
|
255
|
-
|
|
256
258
|
if @options[:log_requests]
|
|
257
259
|
require 'puma/commonlogger'
|
|
258
260
|
logger = @options[:logger]
|
|
@@ -275,8 +277,15 @@ module Puma
|
|
|
275
277
|
@plugins.create name
|
|
276
278
|
end
|
|
277
279
|
|
|
278
|
-
def run_hooks(key, arg)
|
|
279
|
-
@options.all_of(key).each
|
|
280
|
+
def run_hooks(key, arg, events)
|
|
281
|
+
@options.all_of(key).each do |b|
|
|
282
|
+
begin
|
|
283
|
+
b.call arg
|
|
284
|
+
rescue => e
|
|
285
|
+
events.log "WARNING hook #{key} failed with exception (#{e.class}) #{e.message}"
|
|
286
|
+
events.debug e.backtrace.join("\n")
|
|
287
|
+
end
|
|
288
|
+
end
|
|
280
289
|
end
|
|
281
290
|
|
|
282
291
|
def self.temp_path
|
|
@@ -332,29 +341,9 @@ module Puma
|
|
|
332
341
|
end
|
|
333
342
|
|
|
334
343
|
def self.random_token
|
|
335
|
-
|
|
336
|
-
require 'openssl'
|
|
337
|
-
rescue LoadError
|
|
338
|
-
end
|
|
339
|
-
|
|
340
|
-
count = 16
|
|
341
|
-
|
|
342
|
-
bytes = nil
|
|
343
|
-
|
|
344
|
-
if defined? OpenSSL::Random
|
|
345
|
-
bytes = OpenSSL::Random.random_bytes(count)
|
|
346
|
-
elsif File.exist?("/dev/urandom")
|
|
347
|
-
File.open('/dev/urandom') { |f| bytes = f.read(count) }
|
|
348
|
-
end
|
|
349
|
-
|
|
350
|
-
if bytes
|
|
351
|
-
token = "".dup
|
|
352
|
-
bytes.each_byte { |b| token << b.to_s(16) }
|
|
353
|
-
else
|
|
354
|
-
token = (0..count).to_a.map { rand(255).to_s(16) }.join
|
|
355
|
-
end
|
|
344
|
+
require 'securerandom' unless defined?(SecureRandom)
|
|
356
345
|
|
|
357
|
-
|
|
346
|
+
SecureRandom.hex(16)
|
|
358
347
|
end
|
|
359
348
|
end
|
|
360
349
|
end
|
data/lib/puma/const.rb
CHANGED
|
@@ -76,7 +76,7 @@ module Puma
|
|
|
76
76
|
508 => 'Loop Detected',
|
|
77
77
|
510 => 'Not Extended',
|
|
78
78
|
511 => 'Network Authentication Required'
|
|
79
|
-
}
|
|
79
|
+
}
|
|
80
80
|
|
|
81
81
|
# For some HTTP status codes the client only expects headers.
|
|
82
82
|
#
|
|
@@ -85,7 +85,7 @@ module Puma
|
|
|
85
85
|
204 => true,
|
|
86
86
|
205 => true,
|
|
87
87
|
304 => true
|
|
88
|
-
}
|
|
88
|
+
}
|
|
89
89
|
|
|
90
90
|
# Frequently used constants when constructing requests or responses. Many times
|
|
91
91
|
# the constant just refers to a string with the same contents. Using these constants
|
|
@@ -100,8 +100,9 @@ module Puma
|
|
|
100
100
|
# too taxing on performance.
|
|
101
101
|
module Const
|
|
102
102
|
|
|
103
|
-
PUMA_VERSION = VERSION = "
|
|
104
|
-
CODE_NAME = "
|
|
103
|
+
PUMA_VERSION = VERSION = "5.0.0".freeze
|
|
104
|
+
CODE_NAME = "Spoony Bard".freeze
|
|
105
|
+
|
|
105
106
|
PUMA_SERVER_STRING = ['puma', PUMA_VERSION, CODE_NAME].join(' ').freeze
|
|
106
107
|
|
|
107
108
|
FAST_TRACK_KA_TIMEOUT = 0.2
|
|
@@ -144,11 +145,9 @@ module Puma
|
|
|
144
145
|
408 => "HTTP/1.1 408 Request Timeout\r\nConnection: close\r\nServer: Puma #{PUMA_VERSION}\r\n\r\n".freeze,
|
|
145
146
|
# Indicate that there was an internal error, obviously.
|
|
146
147
|
500 => "HTTP/1.1 500 Internal Server Error\r\n\r\n".freeze,
|
|
147
|
-
# Incorrect or invalid header value
|
|
148
|
-
501 => "HTTP/1.1 501 Not Implemented\r\n\r\n".freeze,
|
|
149
148
|
# A common header for indicating the server is too busy. Not used yet.
|
|
150
149
|
503 => "HTTP/1.1 503 Service Unavailable\r\n\r\nBUSY".freeze
|
|
151
|
-
}
|
|
150
|
+
}
|
|
152
151
|
|
|
153
152
|
# The basic max request size we'll try to read.
|
|
154
153
|
CHUNK_SIZE = 16 * 1024
|
|
@@ -177,7 +176,6 @@ module Puma
|
|
|
177
176
|
PORT_443 = "443".freeze
|
|
178
177
|
LOCALHOST = "localhost".freeze
|
|
179
178
|
LOCALHOST_IP = "127.0.0.1".freeze
|
|
180
|
-
LOCALHOST_ADDR = "127.0.0.1:0".freeze
|
|
181
179
|
|
|
182
180
|
SERVER_PROTOCOL = "SERVER_PROTOCOL".freeze
|
|
183
181
|
HTTP_11 = "HTTP/1.1".freeze
|
data/lib/puma/control_cli.rb
CHANGED
|
@@ -11,7 +11,10 @@ require 'socket'
|
|
|
11
11
|
module Puma
|
|
12
12
|
class ControlCLI
|
|
13
13
|
|
|
14
|
-
COMMANDS = %w{halt restart phased-restart start stats status stop reload-worker-directory gc gc-stats}
|
|
14
|
+
COMMANDS = %w{halt restart phased-restart start stats status stop reload-worker-directory gc gc-stats thread-backtraces refork}
|
|
15
|
+
|
|
16
|
+
# @version 5.0.0
|
|
17
|
+
PRINTABLE_COMMANDS = %w{gc-stats stats thread-backtraces}
|
|
15
18
|
|
|
16
19
|
def initialize(argv, stdout=STDOUT, stderr=STDERR)
|
|
17
20
|
@state = nil
|
|
@@ -22,7 +25,7 @@ module Puma
|
|
|
22
25
|
@control_auth_token = nil
|
|
23
26
|
@config_file = nil
|
|
24
27
|
@command = nil
|
|
25
|
-
@environment = ENV['RACK_ENV']
|
|
28
|
+
@environment = ENV['RACK_ENV'] || ENV['RAILS_ENV']
|
|
26
29
|
|
|
27
30
|
@argv = argv.dup
|
|
28
31
|
@stdout = stdout
|
|
@@ -81,6 +84,15 @@ module Puma
|
|
|
81
84
|
|
|
82
85
|
@command = argv.shift
|
|
83
86
|
|
|
87
|
+
# check presence of command
|
|
88
|
+
unless @command
|
|
89
|
+
raise "Available commands: #{COMMANDS.join(", ")}"
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
unless COMMANDS.include? @command
|
|
93
|
+
raise "Invalid command: #{@command}"
|
|
94
|
+
end
|
|
95
|
+
|
|
84
96
|
unless @config_file == '-'
|
|
85
97
|
environment = @environment || 'development'
|
|
86
98
|
|
|
@@ -99,16 +111,6 @@ module Puma
|
|
|
99
111
|
@pidfile ||= config.options[:pidfile]
|
|
100
112
|
end
|
|
101
113
|
end
|
|
102
|
-
|
|
103
|
-
# check present of command
|
|
104
|
-
unless @command
|
|
105
|
-
raise "Available commands: #{COMMANDS.join(", ")}"
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
unless COMMANDS.include? @command
|
|
109
|
-
raise "Invalid command: #{@command}"
|
|
110
|
-
end
|
|
111
|
-
|
|
112
114
|
rescue => e
|
|
113
115
|
@stdout.puts e.message
|
|
114
116
|
exit 1
|
|
@@ -145,8 +147,9 @@ module Puma
|
|
|
145
147
|
require 'openssl'
|
|
146
148
|
OpenSSL::SSL::SSLSocket.new(
|
|
147
149
|
TCPSocket.new(uri.host, uri.port),
|
|
148
|
-
OpenSSL::SSL::SSLContext.new
|
|
149
|
-
|
|
150
|
+
OpenSSL::SSL::SSLContext.new)
|
|
151
|
+
.tap { |ssl| ssl.sync_close = true } # default is false
|
|
152
|
+
.tap(&:connect)
|
|
150
153
|
when "tcp"
|
|
151
154
|
TCPSocket.new uri.host, uri.port
|
|
152
155
|
when "unix"
|
|
@@ -187,10 +190,16 @@ module Puma
|
|
|
187
190
|
end
|
|
188
191
|
|
|
189
192
|
message "Command #{@command} sent success"
|
|
190
|
-
message response.last if @command
|
|
193
|
+
message response.last if PRINTABLE_COMMANDS.include?(@command)
|
|
191
194
|
end
|
|
192
195
|
ensure
|
|
193
|
-
|
|
196
|
+
if server
|
|
197
|
+
if uri.scheme == "ssl"
|
|
198
|
+
server.sysclose
|
|
199
|
+
else
|
|
200
|
+
server.close unless server.closed?
|
|
201
|
+
end
|
|
202
|
+
end
|
|
194
203
|
end
|
|
195
204
|
|
|
196
205
|
def send_signal
|
|
@@ -231,6 +240,9 @@ module Puma
|
|
|
231
240
|
|
|
232
241
|
return
|
|
233
242
|
|
|
243
|
+
when "refork"
|
|
244
|
+
Process.kill "SIGURG", @pid
|
|
245
|
+
|
|
234
246
|
else
|
|
235
247
|
return
|
|
236
248
|
end
|
|
@@ -262,7 +274,7 @@ module Puma
|
|
|
262
274
|
exit 1
|
|
263
275
|
end
|
|
264
276
|
|
|
265
|
-
|
|
277
|
+
private
|
|
266
278
|
def start
|
|
267
279
|
require 'puma/cli'
|
|
268
280
|
|
data/lib/puma/detect.rb
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Puma
|
|
4
|
+
# at present, MiniSSL::Engine is only defined in extension code, not in minissl.rb
|
|
5
|
+
HAS_SSL = const_defined?(:MiniSSL, false) && MiniSSL.const_defined?(:Engine, false)
|
|
6
|
+
|
|
7
|
+
def self.ssl?
|
|
8
|
+
HAS_SSL
|
|
9
|
+
end
|
|
10
|
+
|
|
4
11
|
IS_JRUBY = defined?(JRUBY_VERSION)
|
|
5
12
|
|
|
6
13
|
def self.jruby?
|
|
@@ -12,4 +19,14 @@ module Puma
|
|
|
12
19
|
def self.windows?
|
|
13
20
|
IS_WINDOWS
|
|
14
21
|
end
|
|
22
|
+
|
|
23
|
+
# @version 5.0.0
|
|
24
|
+
def self.mri?
|
|
25
|
+
RUBY_ENGINE == 'ruby' || RUBY_ENGINE.nil?
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# @version 5.0.0
|
|
29
|
+
def self.forkable?
|
|
30
|
+
::Process.respond_to?(:fork)
|
|
31
|
+
end
|
|
15
32
|
end
|