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/launcher.rb
CHANGED
|
@@ -47,8 +47,9 @@ module Puma
|
|
|
47
47
|
@original_argv = @argv.dup
|
|
48
48
|
@config = conf
|
|
49
49
|
|
|
50
|
-
@binder = Binder.new(@events)
|
|
51
|
-
@binder.
|
|
50
|
+
@binder = Binder.new(@events, conf)
|
|
51
|
+
@binder.create_inherited_fds(ENV).each { |k| ENV.delete k }
|
|
52
|
+
@binder.create_activated_fds(ENV).each { |k| ENV.delete k }
|
|
52
53
|
|
|
53
54
|
@environment = conf.environment
|
|
54
55
|
|
|
@@ -69,10 +70,6 @@ module Puma
|
|
|
69
70
|
unsupported "worker mode not supported on #{RUBY_ENGINE} on this platform"
|
|
70
71
|
end
|
|
71
72
|
|
|
72
|
-
if @options[:daemon] && Puma.windows?
|
|
73
|
-
unsupported 'daemon mode not supported on Windows'
|
|
74
|
-
end
|
|
75
|
-
|
|
76
73
|
Dir.chdir(@restart_dir)
|
|
77
74
|
|
|
78
75
|
prune_bundler if prune_bundler?
|
|
@@ -105,6 +102,7 @@ module Puma
|
|
|
105
102
|
write_pid
|
|
106
103
|
|
|
107
104
|
path = @options[:state]
|
|
105
|
+
permission = @options[:state_permission]
|
|
108
106
|
return unless path
|
|
109
107
|
|
|
110
108
|
require 'puma/state_file'
|
|
@@ -113,8 +111,9 @@ module Puma
|
|
|
113
111
|
sf.pid = Process.pid
|
|
114
112
|
sf.control_url = @options[:control_url]
|
|
115
113
|
sf.control_auth_token = @options[:control_auth_token]
|
|
114
|
+
sf.running_from = File.expand_path('.')
|
|
116
115
|
|
|
117
|
-
sf.save path
|
|
116
|
+
sf.save path, permission
|
|
118
117
|
end
|
|
119
118
|
|
|
120
119
|
# Delete the configured pidfile
|
|
@@ -174,22 +173,24 @@ module Puma
|
|
|
174
173
|
case @status
|
|
175
174
|
when :halt
|
|
176
175
|
log "* Stopping immediately!"
|
|
176
|
+
@runner.stop_control
|
|
177
177
|
when :run, :stop
|
|
178
178
|
graceful_stop
|
|
179
179
|
when :restart
|
|
180
180
|
log "* Restarting..."
|
|
181
181
|
ENV.replace(previous_env)
|
|
182
|
-
@runner.
|
|
182
|
+
@runner.stop_control
|
|
183
183
|
restart!
|
|
184
184
|
when :exit
|
|
185
185
|
# nothing
|
|
186
186
|
end
|
|
187
|
-
@
|
|
187
|
+
close_binder_listeners unless @status == :restart
|
|
188
188
|
end
|
|
189
189
|
|
|
190
|
-
# Return
|
|
191
|
-
|
|
192
|
-
|
|
190
|
+
# Return all tcp ports the launcher may be using, TCP or SSL
|
|
191
|
+
# @version 5.0.0
|
|
192
|
+
def connected_ports
|
|
193
|
+
@binder.connected_ports
|
|
193
194
|
end
|
|
194
195
|
|
|
195
196
|
def restart_args
|
|
@@ -202,9 +203,22 @@ module Puma
|
|
|
202
203
|
end
|
|
203
204
|
|
|
204
205
|
def close_binder_listeners
|
|
206
|
+
@runner.close_control_listeners
|
|
205
207
|
@binder.close_listeners
|
|
206
208
|
end
|
|
207
209
|
|
|
210
|
+
# @version 5.0.0
|
|
211
|
+
def thread_status
|
|
212
|
+
Thread.list.each do |thread|
|
|
213
|
+
name = "Thread: TID-#{thread.object_id.to_s(36)}"
|
|
214
|
+
name += " #{thread['label']}" if thread['label']
|
|
215
|
+
name += " #{thread.name}" if thread.respond_to?(:name) && thread.name
|
|
216
|
+
backtrace = thread.backtrace || ["<no backtrace available>"]
|
|
217
|
+
|
|
218
|
+
yield name, backtrace
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
|
|
208
222
|
private
|
|
209
223
|
|
|
210
224
|
# If configured, write the pid of the current process out
|
|
@@ -225,7 +239,7 @@ module Puma
|
|
|
225
239
|
end
|
|
226
240
|
|
|
227
241
|
def restart!
|
|
228
|
-
@config.run_hooks :on_restart, self
|
|
242
|
+
@config.run_hooks :on_restart, self, @events
|
|
229
243
|
|
|
230
244
|
if Puma.jruby?
|
|
231
245
|
close_binder_listeners
|
|
@@ -241,6 +255,7 @@ module Puma
|
|
|
241
255
|
else
|
|
242
256
|
argv = restart_args
|
|
243
257
|
Dir.chdir(@restart_dir)
|
|
258
|
+
ENV.update(@binder.redirects_for_restart_env)
|
|
244
259
|
argv += [@binder.redirects_for_restart]
|
|
245
260
|
Kernel.exec(*argv)
|
|
246
261
|
end
|
|
@@ -275,6 +290,7 @@ module Puma
|
|
|
275
290
|
end
|
|
276
291
|
|
|
277
292
|
def prune_bundler
|
|
293
|
+
return if ENV['PUMA_BUNDLER_PRUNED']
|
|
278
294
|
return unless defined?(Bundler)
|
|
279
295
|
require_rubygems_min_version!(Gem::Version.new("2.2"), "prune_bundler")
|
|
280
296
|
unless puma_wild_location
|
|
@@ -286,8 +302,10 @@ module Puma
|
|
|
286
302
|
|
|
287
303
|
log '* Pruning Bundler environment'
|
|
288
304
|
home = ENV['GEM_HOME']
|
|
289
|
-
Bundler.
|
|
305
|
+
bundle_gemfile = Bundler.original_env['BUNDLE_GEMFILE']
|
|
306
|
+
with_unbundled_env do
|
|
290
307
|
ENV['GEM_HOME'] = home
|
|
308
|
+
ENV['BUNDLE_GEMFILE'] = bundle_gemfile
|
|
291
309
|
ENV['PUMA_BUNDLER_PRUNED'] = '1'
|
|
292
310
|
args = [Gem.ruby, puma_wild_location, '-I', dirs.join(':'), deps.join(',')] + @original_argv
|
|
293
311
|
# Ruby 2.0+ defaults to true which breaks socket activation
|
|
@@ -323,21 +341,6 @@ module Puma
|
|
|
323
341
|
log "- Goodbye!"
|
|
324
342
|
end
|
|
325
343
|
|
|
326
|
-
def log_thread_status
|
|
327
|
-
Thread.list.each do |thread|
|
|
328
|
-
log "Thread TID-#{thread.object_id.to_s(36)} #{thread['label']}"
|
|
329
|
-
logstr = "Thread: TID-#{thread.object_id.to_s(36)}"
|
|
330
|
-
logstr += " #{thread.name}" if thread.respond_to?(:name)
|
|
331
|
-
log logstr
|
|
332
|
-
|
|
333
|
-
if thread.backtrace
|
|
334
|
-
log thread.backtrace.join("\n")
|
|
335
|
-
else
|
|
336
|
-
log "<no backtrace available>"
|
|
337
|
-
end
|
|
338
|
-
end
|
|
339
|
-
end
|
|
340
|
-
|
|
341
344
|
def set_process_title
|
|
342
345
|
Process.respond_to?(:setproctitle) ? Process.setproctitle(title) : $0 = title
|
|
343
346
|
end
|
|
@@ -456,8 +459,13 @@ module Puma
|
|
|
456
459
|
end
|
|
457
460
|
|
|
458
461
|
begin
|
|
459
|
-
|
|
460
|
-
|
|
462
|
+
unless Puma.jruby? # INFO in use by JVM already
|
|
463
|
+
Signal.trap "SIGINFO" do
|
|
464
|
+
thread_status do |name, backtrace|
|
|
465
|
+
@events.log name
|
|
466
|
+
@events.log backtrace.map { |bt| " #{bt}" }
|
|
467
|
+
end
|
|
468
|
+
end
|
|
461
469
|
end
|
|
462
470
|
rescue Exception
|
|
463
471
|
# Not going to log this one, as SIGINFO is *BSD only and would be pretty annoying
|
|
@@ -471,5 +479,15 @@ module Puma
|
|
|
471
479
|
raise "#{feature} is not supported on your version of RubyGems. " \
|
|
472
480
|
"You must have RubyGems #{min_version}+ to use this feature."
|
|
473
481
|
end
|
|
482
|
+
|
|
483
|
+
# @version 5.0.0
|
|
484
|
+
def with_unbundled_env
|
|
485
|
+
bundler_ver = Gem::Version.new(Bundler::VERSION)
|
|
486
|
+
if bundler_ver < Gem::Version.new('2.1.0')
|
|
487
|
+
Bundler.with_clean_env { yield }
|
|
488
|
+
else
|
|
489
|
+
Bundler.with_unbundled_env { yield }
|
|
490
|
+
end
|
|
491
|
+
end
|
|
474
492
|
end
|
|
475
493
|
end
|
data/lib/puma/minissl.rb
CHANGED
|
@@ -5,8 +5,18 @@ begin
|
|
|
5
5
|
rescue LoadError
|
|
6
6
|
end
|
|
7
7
|
|
|
8
|
+
# need for Puma::MiniSSL::OPENSSL constants used in `HAS_TLS1_3`
|
|
9
|
+
require 'puma/puma_http11'
|
|
10
|
+
|
|
8
11
|
module Puma
|
|
9
12
|
module MiniSSL
|
|
13
|
+
# Define constant at runtime, as it's easy to determine at built time,
|
|
14
|
+
# but Puma could (it shouldn't) be loaded with an older OpenSSL version
|
|
15
|
+
# @version 5.0.0
|
|
16
|
+
HAS_TLS1_3 = !IS_JRUBY &&
|
|
17
|
+
(OPENSSL_VERSION[/ \d+\.\d+\.\d+/].split('.').map(&:to_i) <=> [1,1,1]) != -1 &&
|
|
18
|
+
(OPENSSL_LIBRARY_VERSION[/ \d+\.\d+\.\d+/].split('.').map(&:to_i) <=> [1,1,1]) !=-1
|
|
19
|
+
|
|
10
20
|
class Socket
|
|
11
21
|
def initialize(socket, engine)
|
|
12
22
|
@socket = socket
|
|
@@ -22,6 +32,26 @@ module Puma
|
|
|
22
32
|
@socket.closed?
|
|
23
33
|
end
|
|
24
34
|
|
|
35
|
+
# Returns a two element array,
|
|
36
|
+
# first is protocol version (SSL_get_version),
|
|
37
|
+
# second is 'handshake' state (SSL_state_string)
|
|
38
|
+
#
|
|
39
|
+
# Used for dropping tcp connections to ssl.
|
|
40
|
+
# See OpenSSL ssl/ssl_stat.c SSL_state_string for info
|
|
41
|
+
# @version 5.0.0
|
|
42
|
+
#
|
|
43
|
+
def ssl_version_state
|
|
44
|
+
IS_JRUBY ? [nil, nil] : @engine.ssl_vers_st
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Used to check the handshake status, in particular when a TCP connection
|
|
48
|
+
# is made with TLSv1.3 as an available protocol
|
|
49
|
+
# @version 5.0.0
|
|
50
|
+
def bad_tlsv1_3?
|
|
51
|
+
HAS_TLS1_3 && @engine.ssl_vers_st == ['TLSv1.3', 'SSLERR']
|
|
52
|
+
end
|
|
53
|
+
private :bad_tlsv1_3?
|
|
54
|
+
|
|
25
55
|
def readpartial(size)
|
|
26
56
|
while true
|
|
27
57
|
output = @engine.read
|
|
@@ -41,6 +71,7 @@ module Puma
|
|
|
41
71
|
|
|
42
72
|
def engine_read_all
|
|
43
73
|
output = @engine.read
|
|
74
|
+
raise SSLError.exception "HTTP connection?" if bad_tlsv1_3?
|
|
44
75
|
while output and additional_output = @engine.read
|
|
45
76
|
output << additional_output
|
|
46
77
|
end
|
|
@@ -107,14 +138,18 @@ module Puma
|
|
|
107
138
|
alias_method :<<, :write
|
|
108
139
|
|
|
109
140
|
# This is a temporary fix to deal with websockets code using
|
|
110
|
-
# write_nonblock.
|
|
141
|
+
# write_nonblock.
|
|
142
|
+
|
|
143
|
+
# The problem with implementing it properly
|
|
111
144
|
# is that it means we'd have to have the ability to rewind
|
|
112
145
|
# an engine because after we write+extract, the socket
|
|
113
146
|
# write_nonblock call might raise an exception and later
|
|
114
147
|
# code would pass the same data in, but the engine would think
|
|
115
|
-
# it had already written the data in.
|
|
116
|
-
#
|
|
117
|
-
#
|
|
148
|
+
# it had already written the data in.
|
|
149
|
+
#
|
|
150
|
+
# So for the time being (and since write blocking is quite rare),
|
|
151
|
+
# go ahead and actually block in write_nonblock.
|
|
152
|
+
#
|
|
118
153
|
def write_nonblock(data, *_)
|
|
119
154
|
write data
|
|
120
155
|
end
|
|
@@ -125,11 +160,14 @@ module Puma
|
|
|
125
160
|
|
|
126
161
|
def read_and_drop(timeout = 1)
|
|
127
162
|
return :timeout unless IO.select([@socket], nil, nil, timeout)
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
163
|
+
case @socket.read_nonblock(1024, exception: false)
|
|
164
|
+
when nil
|
|
165
|
+
:eof
|
|
166
|
+
when :wait_readable
|
|
167
|
+
:eagain
|
|
168
|
+
else
|
|
169
|
+
:drop
|
|
170
|
+
end
|
|
133
171
|
end
|
|
134
172
|
|
|
135
173
|
def should_drop_bytes?
|
|
@@ -141,9 +179,7 @@ module Puma
|
|
|
141
179
|
# Read any drop any partially initialized sockets and any received bytes during shutdown.
|
|
142
180
|
# Don't let this socket hold this loop forever.
|
|
143
181
|
# If it can't send more packets within 1s, then give up.
|
|
144
|
-
while should_drop_bytes?
|
|
145
|
-
return if [:timeout, :eof].include?(read_and_drop(1))
|
|
146
|
-
end
|
|
182
|
+
return if [:timeout, :eof].include?(read_and_drop(1)) while should_drop_bytes?
|
|
147
183
|
rescue IOError, SystemCallError
|
|
148
184
|
Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue
|
|
149
185
|
# nothing
|
|
@@ -166,12 +202,13 @@ module Puma
|
|
|
166
202
|
end
|
|
167
203
|
end
|
|
168
204
|
|
|
169
|
-
if
|
|
205
|
+
if IS_JRUBY
|
|
206
|
+
OPENSSL_NO_SSL3 = false
|
|
207
|
+
OPENSSL_NO_TLS1 = false
|
|
208
|
+
|
|
170
209
|
class SSLError < StandardError
|
|
171
210
|
# Define this for jruby even though it isn't used.
|
|
172
211
|
end
|
|
173
|
-
|
|
174
|
-
def self.check; end
|
|
175
212
|
end
|
|
176
213
|
|
|
177
214
|
class Context
|
|
@@ -183,7 +220,7 @@ module Puma
|
|
|
183
220
|
@no_tlsv1_1 = false
|
|
184
221
|
end
|
|
185
222
|
|
|
186
|
-
if
|
|
223
|
+
if IS_JRUBY
|
|
187
224
|
# jruby-specific Context properties: java uses a keystore and password pair rather than a cert/key pair
|
|
188
225
|
attr_reader :keystore
|
|
189
226
|
attr_accessor :keystore_pass
|
|
@@ -228,13 +265,13 @@ module Puma
|
|
|
228
265
|
|
|
229
266
|
# disables TLSv1
|
|
230
267
|
def no_tlsv1=(tlsv1)
|
|
231
|
-
raise ArgumentError, "Invalid value of no_tlsv1" unless ['true', 'false', true, false].include?(tlsv1)
|
|
268
|
+
raise ArgumentError, "Invalid value of no_tlsv1=" unless ['true', 'false', true, false].include?(tlsv1)
|
|
232
269
|
@no_tlsv1 = tlsv1
|
|
233
270
|
end
|
|
234
271
|
|
|
235
272
|
# disables TLSv1 and TLSv1.1. Overrides `#no_tlsv1=`
|
|
236
273
|
def no_tlsv1_1=(tlsv1_1)
|
|
237
|
-
raise ArgumentError, "Invalid value of
|
|
274
|
+
raise ArgumentError, "Invalid value of no_tlsv1_1=" unless ['true', 'false', true, false].include?(tlsv1_1)
|
|
238
275
|
@no_tlsv1_1 = tlsv1_1
|
|
239
276
|
end
|
|
240
277
|
|
|
@@ -270,6 +307,11 @@ module Puma
|
|
|
270
307
|
Socket.new io, engine
|
|
271
308
|
end
|
|
272
309
|
|
|
310
|
+
# @version 5.0.0
|
|
311
|
+
def addr
|
|
312
|
+
@socket.addr
|
|
313
|
+
end
|
|
314
|
+
|
|
273
315
|
def close
|
|
274
316
|
@socket.close unless @socket.closed? # closed? call is for Windows
|
|
275
317
|
end
|
data/lib/puma/null_io.rb
CHANGED
|
File without changes
|
data/lib/puma/plugin.rb
CHANGED
|
@@ -10,7 +10,7 @@ module Puma
|
|
|
10
10
|
|
|
11
11
|
def create(name)
|
|
12
12
|
if cls = Plugins.find(name)
|
|
13
|
-
plugin = cls.new
|
|
13
|
+
plugin = cls.new
|
|
14
14
|
@instances << plugin
|
|
15
15
|
return plugin
|
|
16
16
|
end
|
|
@@ -104,17 +104,8 @@ module Puma
|
|
|
104
104
|
Plugins.register name, cls
|
|
105
105
|
end
|
|
106
106
|
|
|
107
|
-
def initialize(loader)
|
|
108
|
-
@loader = loader
|
|
109
|
-
end
|
|
110
|
-
|
|
111
107
|
def in_background(&blk)
|
|
112
108
|
Plugins.add_background blk
|
|
113
109
|
end
|
|
114
|
-
|
|
115
|
-
def workers_supported?
|
|
116
|
-
return false if Puma.jruby? || Puma.windows?
|
|
117
|
-
true
|
|
118
|
-
end
|
|
119
110
|
end
|
|
120
111
|
end
|
data/lib/puma/rack/builder.rb
CHANGED
|
@@ -67,10 +67,6 @@ module Puma::Rack
|
|
|
67
67
|
options[:environment] = e
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
opts.on("-D", "--daemonize", "run daemonized in the background") { |d|
|
|
71
|
-
options[:daemonize] = d ? true : false
|
|
72
|
-
}
|
|
73
|
-
|
|
74
70
|
opts.on("-P", "--pid FILE", "file to store PID") { |f|
|
|
75
71
|
options[:pid] = ::File.expand_path(f)
|
|
76
72
|
}
|
data/lib/puma/rack/urlmap.rb
CHANGED
|
File without changes
|
data/lib/puma/rack_default.rb
CHANGED
|
File without changes
|
data/lib/puma/reactor.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'puma/util'
|
|
4
|
-
require 'puma/minissl'
|
|
4
|
+
require 'puma/minissl' if ::Puma::HAS_SSL
|
|
5
5
|
|
|
6
6
|
require 'nio'
|
|
7
7
|
|
|
@@ -189,7 +189,12 @@ module Puma
|
|
|
189
189
|
if submon.value == @ready
|
|
190
190
|
false
|
|
191
191
|
else
|
|
192
|
-
submon.value.
|
|
192
|
+
if submon.value.can_close?
|
|
193
|
+
submon.value.close
|
|
194
|
+
else
|
|
195
|
+
# Pass remaining open client connections to the thread pool.
|
|
196
|
+
@app_pool << submon.value
|
|
197
|
+
end
|
|
193
198
|
begin
|
|
194
199
|
selector.deregister submon.value
|
|
195
200
|
rescue IOError
|
|
@@ -247,7 +252,7 @@ module Puma
|
|
|
247
252
|
c.close
|
|
248
253
|
clear_monitor mon
|
|
249
254
|
|
|
250
|
-
@events.ssl_error
|
|
255
|
+
@events.ssl_error e, addr, cert
|
|
251
256
|
|
|
252
257
|
# The client doesn't know HTTP well
|
|
253
258
|
rescue HttpParserError => e
|
|
@@ -258,7 +263,7 @@ module Puma
|
|
|
258
263
|
|
|
259
264
|
clear_monitor mon
|
|
260
265
|
|
|
261
|
-
@events.parse_error
|
|
266
|
+
@events.parse_error e, c
|
|
262
267
|
rescue StandardError => e
|
|
263
268
|
@server.lowlevel_error(e, c.env)
|
|
264
269
|
|
data/lib/puma/runner.rb
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
require 'puma/server'
|
|
4
4
|
require 'puma/const'
|
|
5
|
-
require 'puma/minissl/context_builder'
|
|
6
5
|
|
|
7
6
|
module Puma
|
|
8
7
|
# Generic class that is used by `Puma::Cluster` and `Puma::Single` to
|
|
@@ -18,10 +17,6 @@ module Puma
|
|
|
18
17
|
@started_at = Time.now
|
|
19
18
|
end
|
|
20
19
|
|
|
21
|
-
def daemon?
|
|
22
|
-
@options[:daemon]
|
|
23
|
-
end
|
|
24
|
-
|
|
25
20
|
def development?
|
|
26
21
|
@options[:environment] == "development"
|
|
27
22
|
end
|
|
@@ -34,7 +29,8 @@ module Puma
|
|
|
34
29
|
@events.log str
|
|
35
30
|
end
|
|
36
31
|
|
|
37
|
-
|
|
32
|
+
# @version 5.0.0
|
|
33
|
+
def stop_control
|
|
38
34
|
@control.stop(true) if @control
|
|
39
35
|
end
|
|
40
36
|
|
|
@@ -52,8 +48,6 @@ module Puma
|
|
|
52
48
|
|
|
53
49
|
require 'puma/app/status'
|
|
54
50
|
|
|
55
|
-
uri = URI.parse str
|
|
56
|
-
|
|
57
51
|
if token = @options[:control_auth_token]
|
|
58
52
|
token = nil if token.empty? || token == 'none'
|
|
59
53
|
end
|
|
@@ -64,30 +58,17 @@ module Puma
|
|
|
64
58
|
control.min_threads = 0
|
|
65
59
|
control.max_threads = 1
|
|
66
60
|
|
|
67
|
-
|
|
68
|
-
when "ssl"
|
|
69
|
-
log "* Starting control server on #{str}"
|
|
70
|
-
params = Util.parse_query uri.query
|
|
71
|
-
ctx = MiniSSL::ContextBuilder.new(params, @events).context
|
|
72
|
-
|
|
73
|
-
control.add_ssl_listener uri.host, uri.port, ctx
|
|
74
|
-
when "tcp"
|
|
75
|
-
log "* Starting control server on #{str}"
|
|
76
|
-
control.add_tcp_listener uri.host, uri.port
|
|
77
|
-
when "unix"
|
|
78
|
-
log "* Starting control server on #{str}"
|
|
79
|
-
path = "#{uri.host}#{uri.path}"
|
|
80
|
-
mask = @options[:control_url_umask]
|
|
81
|
-
|
|
82
|
-
control.add_unix_listener path, mask
|
|
83
|
-
else
|
|
84
|
-
error "Invalid control URI: #{str}"
|
|
85
|
-
end
|
|
61
|
+
control.binder.parse [str], self, 'Starting control server'
|
|
86
62
|
|
|
87
63
|
control.run
|
|
88
64
|
@control = control
|
|
89
65
|
end
|
|
90
66
|
|
|
67
|
+
# @version 5.0.0
|
|
68
|
+
def close_control_listeners
|
|
69
|
+
@control.binder.close_listeners if @control
|
|
70
|
+
end
|
|
71
|
+
|
|
91
72
|
def ruby_engine
|
|
92
73
|
if !defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby"
|
|
93
74
|
"ruby #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
|
|
@@ -108,10 +89,6 @@ module Puma
|
|
|
108
89
|
log "* Version #{Puma::Const::PUMA_VERSION} (#{ruby_engine}), codename: #{Puma::Const::CODE_NAME}"
|
|
109
90
|
log "* Min threads: #{min_t}, max threads: #{max_t}"
|
|
110
91
|
log "* Environment: #{ENV['RACK_ENV']}"
|
|
111
|
-
|
|
112
|
-
if @options[:mode] == :tcp
|
|
113
|
-
log "* Mode: Lopez Express (tcp)"
|
|
114
|
-
end
|
|
115
92
|
end
|
|
116
93
|
|
|
117
94
|
def redirected_io?
|
|
@@ -150,7 +127,6 @@ module Puma
|
|
|
150
127
|
exit 1
|
|
151
128
|
end
|
|
152
129
|
|
|
153
|
-
# Load the app before we daemonize.
|
|
154
130
|
begin
|
|
155
131
|
@app = @launcher.config.app
|
|
156
132
|
rescue Exception => e
|
|
@@ -174,10 +150,6 @@ module Puma
|
|
|
174
150
|
server.max_threads = max_t
|
|
175
151
|
server.inherit_binder @launcher.binder
|
|
176
152
|
|
|
177
|
-
if @options[:mode] == :tcp
|
|
178
|
-
server.tcp_mode!
|
|
179
|
-
end
|
|
180
|
-
|
|
181
153
|
if @options[:early_hints]
|
|
182
154
|
server.early_hints = true
|
|
183
155
|
end
|