jun-puma 1.0.0-java → 1.0.1-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/puma/client.rb CHANGED
@@ -51,14 +51,6 @@ module Puma
51
51
  CHUNK_VALID_ENDING = Const::LINE_END
52
52
  CHUNK_VALID_ENDING_SIZE = CHUNK_VALID_ENDING.bytesize
53
53
 
54
- # The maximum number of bytes we'll buffer looking for a valid
55
- # chunk header.
56
- MAX_CHUNK_HEADER_SIZE = 4096
57
-
58
- # The maximum amount of excess data the client sends
59
- # using chunk size extensions before we abort the connection.
60
- MAX_CHUNK_EXCESS = 16 * 1024
61
-
62
54
  # Content-Length header value validation
63
55
  CONTENT_LENGTH_VALUE_INVALID = /[^\d]/.freeze
64
56
 
@@ -160,6 +152,8 @@ module Puma
160
152
  @read_header = true
161
153
  @read_proxy = !!@expect_proxy_proto
162
154
  @env = @proto_env.dup
155
+ @body = nil
156
+ @tempfile = nil
163
157
  @parsed_bytes = 0
164
158
  @ready = false
165
159
  @body_remain = 0
@@ -188,11 +182,11 @@ module Puma
188
182
  rescue IOError
189
183
  # swallow it
190
184
  end
185
+
191
186
  end
192
187
  end
193
188
 
194
189
  def close
195
- tempfile_close
196
190
  begin
197
191
  @io.close
198
192
  rescue IOError, Errno::EBADF
@@ -200,15 +194,6 @@ module Puma
200
194
  end
201
195
  end
202
196
 
203
- def tempfile_close
204
- tf_path = @tempfile&.path
205
- @tempfile&.close
206
- File.unlink(tf_path) if tf_path
207
- @tempfile = nil
208
- @body = nil
209
- rescue Errno::ENOENT, IOError
210
- end
211
-
212
197
  # If necessary, read the PROXY protocol from the buffer. Returns
213
198
  # false if more data is needed.
214
199
  def try_to_parse_proxy_protocol
@@ -247,7 +232,6 @@ module Puma
247
232
 
248
233
  return read_body if in_data_phase
249
234
 
250
- data = nil
251
235
  begin
252
236
  data = @io.read_nonblock(CHUNK_SIZE)
253
237
  rescue IO::WaitReadable
@@ -411,33 +395,18 @@ module Puma
411
395
  return true
412
396
  end
413
397
 
414
- content_length = cl.to_i
415
-
416
- remain = content_length - body.bytesize
398
+ remain = cl.to_i - body.bytesize
417
399
 
418
400
  if remain <= 0
419
- # Part of the body is a pipelined request OR garbage. We'll deal with that later.
420
- if content_length == 0
421
- @body = EmptyBody
422
- if body.empty?
423
- @buffer = nil
424
- else
425
- @buffer = body
426
- end
427
- elsif remain == 0
428
- @body = StringIO.new body
429
- @buffer = nil
430
- else
431
- @body = StringIO.new(body[0,content_length])
432
- @buffer = body[content_length..-1]
433
- end
401
+ @body = StringIO.new(body)
402
+ @buffer = nil
434
403
  set_ready
435
404
  return true
436
405
  end
437
406
 
438
407
  if remain > MAX_BODY
439
- @body = Tempfile.create(Const::PUMA_TMP_BASE)
440
- File.unlink @body.path unless IS_WINDOWS
408
+ @body = Tempfile.new(Const::PUMA_TMP_BASE)
409
+ @body.unlink
441
410
  @body.binmode
442
411
  @tempfile = @body
443
412
  else
@@ -527,10 +496,9 @@ module Puma
527
496
  @chunked_body = true
528
497
  @partial_part_left = 0
529
498
  @prev_chunk = ""
530
- @excess_cr = 0
531
499
 
532
- @body = Tempfile.create(Const::PUMA_TMP_BASE)
533
- File.unlink @body.path unless IS_WINDOWS
500
+ @body = Tempfile.new(Const::PUMA_TMP_BASE)
501
+ @body.unlink
534
502
  @body.binmode
535
503
  @tempfile = @body
536
504
  @chunked_content_length = 0
@@ -609,20 +577,6 @@ module Puma
609
577
  end
610
578
  end
611
579
 
612
- # Track the excess as a function of the size of the
613
- # header vs the size of the actual data. Excess can
614
- # go negative (and is expected to) when the body is
615
- # significant.
616
- # The additional of chunk_hex.size and 2 compensates
617
- # for a client sending 1 byte in a chunked body over
618
- # a long period of time, making sure that that client
619
- # isn't accidentally eventually punished.
620
- @excess_cr += (line.size - len - chunk_hex.size - 2)
621
-
622
- if @excess_cr >= MAX_CHUNK_EXCESS
623
- raise HttpParserError, "Maximum chunk excess detected"
624
- end
625
-
626
580
  len += 2
627
581
 
628
582
  part = io.read(len)
@@ -650,10 +604,6 @@ module Puma
650
604
  @partial_part_left = len - part.size
651
605
  end
652
606
  else
653
- if @prev_chunk.size + line.size >= MAX_CHUNK_HEADER_SIZE
654
- raise HttpParserError, "maximum size of chunk header exceeded"
655
- end
656
-
657
607
  @prev_chunk = line
658
608
  return false
659
609
  end
@@ -92,21 +92,21 @@ module Puma
92
92
  restart_server << true << false
93
93
  else # fork worker
94
94
  worker_pids << pid = spawn_worker(idx)
95
- @worker_write << "#{Puma::Const::PipeRequest::FORK}#{pid}:#{idx}\n" rescue nil
95
+ @worker_write << "f#{pid}:#{idx}\n" rescue nil
96
96
  end
97
97
  end
98
98
  end
99
99
  end
100
100
 
101
101
  Signal.trap "SIGTERM" do
102
- @worker_write << "#{Puma::Const::PipeRequest::EXTERNAL_TERM}#{Process.pid}\n" rescue nil
102
+ @worker_write << "e#{Process.pid}\n" rescue nil
103
103
  restart_server.clear
104
104
  server.stop
105
105
  restart_server << false
106
106
  end
107
107
 
108
108
  begin
109
- @worker_write << "#{Puma::Const::PipeRequest::BOOT}#{Process.pid}:#{index}\n"
109
+ @worker_write << "b#{Process.pid}:#{index}\n"
110
110
  rescue SystemCallError, IOError
111
111
  Puma::Util.purge_interrupt_queue
112
112
  STDERR.puts "Master seems to have exited, exiting."
@@ -146,8 +146,10 @@ module Puma
146
146
  # Invoke any worker shutdown hooks so they can prevent the worker
147
147
  # exiting until any background operations are completed
148
148
  @config.run_hooks(:before_worker_shutdown, index, @log_writer, @hook_data)
149
+
150
+ Process.kill "SIGTERM", master if server.idle_timeout_reached
149
151
  ensure
150
- @worker_write << "#{Puma::Const::PipeRequest::TERM}#{Process.pid}\n" rescue nil
152
+ @worker_write << "t#{Process.pid}\n" rescue nil
151
153
  @worker_write.close
152
154
  end
153
155
 
@@ -51,12 +51,13 @@ module Puma
51
51
  @term
52
52
  end
53
53
 
54
- STATUS_PATTERN = /{ "backlog":(?<backlog>\d*), "running":(?<running>\d*), "pool_capacity":(?<pool_capacity>\d*), "max_threads": (?<max_threads>\d*), "requests_count": (?<requests_count>\d*) }/
55
- private_constant :STATUS_PATTERN
56
-
57
54
  def ping!(status)
58
55
  @last_checkin = Time.now
59
- @last_status = status.match(STATUS_PATTERN).named_captures.map { |c_name, c| [c_name.to_sym, c.to_i] }.to_h
56
+ captures = status.match(/{ "backlog":(?<backlog>\d*), "running":(?<running>\d*), "pool_capacity":(?<pool_capacity>\d*), "max_threads": (?<max_threads>\d*), "requests_count": (?<requests_count>\d*) }/)
57
+ @last_status = captures.names.inject({}) do |hash, key|
58
+ hash[key.to_sym] = captures[key].to_i
59
+ hash
60
+ end
60
61
  end
61
62
 
62
63
  # @see Puma::Cluster#check_workers
data/lib/puma/cluster.rb CHANGED
@@ -158,10 +158,6 @@ module Puma
158
158
  @workers.all? { |w| w.phase == @phase }
159
159
  end
160
160
 
161
- def all_workers_idle_timed_out?
162
- (@workers.map(&:pid) - idle_timed_out_worker_pids).empty?
163
- end
164
-
165
161
  def check_workers
166
162
  return if @next_check >= Time.now
167
163
 
@@ -421,8 +417,6 @@ module Puma
421
417
 
422
418
  @master_read, @worker_write = read, @wakeup
423
419
 
424
- @options[:worker_write] = @worker_write
425
-
426
420
  @config.run_hooks(:before_fork, nil, @log_writer)
427
421
 
428
422
  spawn_workers
@@ -438,11 +432,6 @@ module Puma
438
432
 
439
433
  while @status == :run
440
434
  begin
441
- if @options[:idle_timeout] && all_workers_idle_timed_out?
442
- log "- All workers reached idle timeout"
443
- break
444
- end
445
-
446
435
  if @phased_restart
447
436
  start_phased_restart
448
437
  @phased_restart = false
@@ -454,17 +443,14 @@ module Puma
454
443
 
455
444
  if read.wait_readable([0, @next_check - Time.now].max)
456
445
  req = read.read_nonblock(1)
457
- next unless req
458
446
 
459
- if req == Puma::Const::PipeRequest::WAKEUP
460
- @next_check = Time.now
461
- next
462
- end
447
+ @next_check = Time.now if req == "!"
448
+ next if !req || req == "!"
463
449
 
464
450
  result = read.gets
465
451
  pid = result.to_i
466
452
 
467
- if req == Puma::Const::PipeRequest::BOOT || req == Puma::Const::PipeRequest::FORK
453
+ if req == "b" || req == "f"
468
454
  pid, idx = result.split(':').map(&:to_i)
469
455
  w = worker_at idx
470
456
  w.pid = pid if w.pid.nil?
@@ -472,17 +458,17 @@ module Puma
472
458
 
473
459
  if w = @workers.find { |x| x.pid == pid }
474
460
  case req
475
- when Puma::Const::PipeRequest::BOOT
461
+ when "b"
476
462
  w.boot!
477
463
  log "- Worker #{w.index} (PID: #{pid}) booted in #{w.uptime.round(2)}s, phase: #{w.phase}"
478
464
  @next_check = Time.now
479
465
  workers_not_booted -= 1
480
- when Puma::Const::PipeRequest::EXTERNAL_TERM
466
+ when "e"
481
467
  # external term, see worker method, Signal.trap "SIGTERM"
482
468
  w.term!
483
- when Puma::Const::PipeRequest::TERM
469
+ when "t"
484
470
  w.term unless w.term?
485
- when Puma::Const::PipeRequest::PING
471
+ when "p"
486
472
  status = result.sub(/^\d+/,'').chomp
487
473
  w.ping!(status)
488
474
  @events.fire(:ping!, w)
@@ -497,23 +483,17 @@ module Puma
497
483
  debug_loaded_extensions("Loaded Extensions - master:") if @log_writer.debug?
498
484
  booted = true
499
485
  end
500
- when Puma::Const::PipeRequest::IDLE
501
- if idle_workers[pid]
502
- idle_workers.delete pid
503
- else
504
- idle_workers[pid] = true
505
- end
506
486
  end
507
487
  else
508
488
  log "! Out-of-sync worker list, no #{pid} worker"
509
489
  end
510
490
  end
511
-
512
491
  if in_phased_restart && workers_not_booted.zero?
513
492
  @events.fire_on_booted!
514
493
  debug_loaded_extensions("Loaded Extensions - master:") if @log_writer.debug?
515
494
  in_phased_restart = false
516
495
  end
496
+
517
497
  rescue Interrupt
518
498
  @status = :stop
519
499
  end
@@ -542,31 +522,10 @@ module Puma
542
522
  # loops thru @workers, removing workers that exited, and calling
543
523
  # `#term` if needed
544
524
  def wait_workers
545
- # Reap all children, known workers or otherwise.
546
- # If puma has PID 1, as it's common in containerized environments,
547
- # then it's responsible for reaping orphaned processes, so we must reap
548
- # all our dead children, regardless of whether they are workers we spawned
549
- # or some reattached processes.
550
- reaped_children = {}
551
- loop do
552
- begin
553
- pid, status = Process.wait2(-1, Process::WNOHANG)
554
- break unless pid
555
- reaped_children[pid] = status
556
- rescue Errno::ECHILD
557
- break
558
- end
559
- end
560
-
561
525
  @workers.reject! do |w|
562
526
  next false if w.pid.nil?
563
527
  begin
564
- # We may need to check the PID individually because:
565
- # 1. From Ruby versions 2.6 to 3.2, `Process.detach` can prevent or delay
566
- # `Process.wait2(-1)` from detecting a terminated process: https://bugs.ruby-lang.org/issues/19837.
567
- # 2. When `fork_worker` is enabled, some worker may not be direct children,
568
- # but grand children. Because of this they won't be reaped by `Process.wait2(-1)`.
569
- if reaped_children.delete(w.pid) || Process.wait(w.pid, Process::WNOHANG)
528
+ if Process.wait(w.pid, Process::WNOHANG)
570
529
  true
571
530
  else
572
531
  w.term if w.term?
@@ -583,11 +542,6 @@ module Puma
583
542
  end
584
543
  end
585
544
  end
586
-
587
- # Log unknown children
588
- reaped_children.each do |pid, status|
589
- log "! reaped unknown child process pid=#{pid} status=#{status}"
590
- end
591
545
  end
592
546
 
593
547
  # @version 5.0.0
@@ -604,13 +558,5 @@ module Puma
604
558
  end
605
559
  end
606
560
  end
607
-
608
- def idle_timed_out_worker_pids
609
- idle_workers.keys
610
- end
611
-
612
- def idle_workers
613
- @idle_workers ||= {}
614
- end
615
561
  end
616
562
  end
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'rack/builder'
3
4
  require_relative 'plugin'
4
5
  require_relative 'const'
5
- require_relative 'dsl'
6
+ # note that dsl is loaded at end of file, requires ConfigDefault constants
6
7
 
7
8
  module Puma
8
9
  # A class used for storing "leveled" configuration options.
@@ -130,7 +131,6 @@ module Puma
130
131
  binds: ['tcp://0.0.0.0:9292'.freeze],
131
132
  clean_thread_locals: false,
132
133
  debug: false,
133
- enable_keep_alives: true,
134
134
  early_hints: nil,
135
135
  environment: 'development'.freeze,
136
136
  # Number of seconds to wait until we get the first data for the request.
@@ -173,8 +173,8 @@ module Puma
173
173
  http_content_length_limit: nil
174
174
  }
175
175
 
176
- def initialize(user_options={}, default_options = {}, env = ENV, &block)
177
- default_options = self.puma_default_options(env).merge(default_options)
176
+ def initialize(user_options={}, default_options = {}, &block)
177
+ default_options = self.puma_default_options.merge(default_options)
178
178
 
179
179
  @options = UserFileDefaultOptions.new(user_options, default_options)
180
180
  @plugins = PluginLoader.new
@@ -186,8 +186,6 @@ module Puma
186
186
  default_options[:preload_app] = (@options[:workers] > 1) && Puma.forkable?
187
187
  end
188
188
 
189
- @puma_bundler_pruned = env.key? 'PUMA_BUNDLER_PRUNED'
190
-
191
189
  if block
192
190
  configure(&block)
193
191
  end
@@ -218,22 +216,22 @@ module Puma
218
216
  self
219
217
  end
220
218
 
221
- def puma_default_options(env = ENV)
219
+ def puma_default_options
222
220
  defaults = DEFAULTS.dup
223
- puma_options_from_env(env).each { |k,v| defaults[k] = v if v }
221
+ puma_options_from_env.each { |k,v| defaults[k] = v if v }
224
222
  defaults
225
223
  end
226
224
 
227
- def puma_options_from_env(env = ENV)
228
- min = env['PUMA_MIN_THREADS'] || env['MIN_THREADS']
229
- max = env['PUMA_MAX_THREADS'] || env['MAX_THREADS']
230
- workers = env['WEB_CONCURRENCY']
225
+ def puma_options_from_env
226
+ min = ENV['PUMA_MIN_THREADS'] || ENV['MIN_THREADS']
227
+ max = ENV['PUMA_MAX_THREADS'] || ENV['MAX_THREADS']
228
+ workers = ENV['WEB_CONCURRENCY']
231
229
 
232
230
  {
233
231
  min_threads: min && Integer(min),
234
232
  max_threads: max && Integer(max),
235
233
  workers: workers && Integer(workers),
236
- environment: env['APP_ENV'] || env['RACK_ENV'] || env['RAILS_ENV'],
234
+ environment: ENV['APP_ENV'] || ENV['RACK_ENV'] || ENV['RAILS_ENV'],
237
235
  }
238
236
  end
239
237
 
@@ -346,7 +344,7 @@ module Puma
346
344
  def rack_builder
347
345
  # Load bundler now if we can so that we can pickup rack from
348
346
  # a Gemfile
349
- if @puma_bundler_pruned
347
+ if ENV.key? 'PUMA_BUNDLER_PRUNED'
350
348
  begin
351
349
  require 'bundler/setup'
352
350
  rescue LoadError
@@ -356,10 +354,11 @@ module Puma
356
354
  begin
357
355
  require 'rack'
358
356
  require 'rack/builder'
359
- ::Rack::Builder
360
357
  rescue LoadError
361
- require_relative 'rack/builder'
362
- Puma::Rack::Builder
358
+ # ok, use builtin version
359
+ return Puma::Rack::Builder
360
+ else
361
+ return ::Rack::Builder
363
362
  end
364
363
  end
365
364
 
@@ -388,3 +387,5 @@ module Puma
388
387
  end
389
388
  end
390
389
  end
390
+
391
+ require_relative 'dsl'
data/lib/puma/const.rb CHANGED
@@ -100,8 +100,8 @@ module Puma
100
100
  # too taxing on performance.
101
101
  module Const
102
102
 
103
- PUMA_VERSION = VERSION = "1.0.0"
104
- CODE_NAME = "The Eagle of Durango - Jun"
103
+ PUMA_VERSION = VERSION = "1.0.1"
104
+ CODE_NAME = "The Eagle of Durango - Jun - 6.4.1"
105
105
 
106
106
  PUMA_SERVER_STRING = ["puma", PUMA_VERSION, CODE_NAME].join(" ").freeze
107
107
 
@@ -281,27 +281,9 @@ module Puma
281
281
  # header values can contain HTAB?
282
282
  ILLEGAL_HEADER_VALUE_REGEX = /[\x00-\x08\x0A-\x1F]/.freeze
283
283
 
284
- # The keys of headers that should not be convert to underscore
285
- # normalized versions. These headers are ignored at the request reading layer,
286
- # but if we normalize them after reading, it's just confusing for the application.
287
- UNMASKABLE_HEADERS = {
288
- "HTTP_TRANSFER,ENCODING" => true,
289
- "HTTP_CONTENT,LENGTH" => true,
290
- }
291
-
292
284
  # Banned keys of response header
293
285
  BANNED_HEADER_KEY = /\A(rack\.|status\z)/.freeze
294
286
 
295
287
  PROXY_PROTOCOL_V1_REGEX = /^PROXY (?:TCP4|TCP6|UNKNOWN) ([^\r]+)\r\n/.freeze
296
-
297
- module PipeRequest
298
- WAKEUP = "!"
299
- BOOT = "b"
300
- FORK = "f"
301
- EXTERNAL_TERM = "e"
302
- TERM = "t"
303
- PING = "p"
304
- IDLE = "i"
305
- end
306
288
  end
307
289
  end
@@ -37,7 +37,7 @@ module Puma
37
37
  # @version 5.0.0
38
38
  PRINTABLE_COMMANDS = %w[gc-stats stats thread-backtraces].freeze
39
39
 
40
- def initialize(argv, stdout=STDOUT, stderr=STDERR, env: ENV)
40
+ def initialize(argv, stdout=STDOUT, stderr=STDERR)
41
41
  @state = nil
42
42
  @quiet = false
43
43
  @pidfile = nil
@@ -46,7 +46,7 @@ module Puma
46
46
  @control_auth_token = nil
47
47
  @config_file = nil
48
48
  @command = nil
49
- @environment = env['APP_ENV'] || env['RACK_ENV'] || env['RAILS_ENV']
49
+ @environment = ENV['APP_ENV'] || ENV['RACK_ENV'] || ENV['RAILS_ENV']
50
50
 
51
51
  @argv = argv.dup
52
52
  @stdout = stdout
@@ -60,7 +60,7 @@ module Puma
60
60
  @state = arg
61
61
  end
62
62
 
63
- o.on "-Q", "--quiet", "Do not display messages" do |arg|
63
+ o.on "-Q", "--quiet", "Not display messages" do |arg|
64
64
  @quiet = true
65
65
  end
66
66
 
@@ -127,7 +127,7 @@ module Puma
127
127
  require_relative 'configuration'
128
128
  require_relative 'log_writer'
129
129
 
130
- config = Puma::Configuration.new({ config_files: [@config_file] }, {} , env)
130
+ config = Puma::Configuration.new({ config_files: [@config_file] }, {})
131
131
  config.load
132
132
  @state ||= config.options[:state]
133
133
  @control_url ||= config.options[:control_url]