puma 5.3.1-java → 5.5.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/server.rb CHANGED
@@ -14,6 +14,7 @@ require 'puma/io_buffer'
14
14
  require 'puma/request'
15
15
 
16
16
  require 'socket'
17
+ require 'io/wait'
17
18
  require 'forwardable'
18
19
 
19
20
  module Puma
@@ -145,7 +146,7 @@ module Puma
145
146
  begin
146
147
  skt.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_CORK, 1) if skt.kind_of? TCPSocket
147
148
  rescue IOError, SystemCallError
148
- Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue
149
+ Puma::Util.purge_interrupt_queue
149
150
  end
150
151
  end
151
152
 
@@ -154,7 +155,7 @@ module Puma
154
155
  begin
155
156
  skt.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_CORK, 0) if skt.kind_of? TCPSocket
156
157
  rescue IOError, SystemCallError
157
- Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue
158
+ Puma::Util.purge_interrupt_queue
158
159
  end
159
160
  end
160
161
  else
@@ -175,7 +176,7 @@ module Puma
175
176
  begin
176
177
  tcp_info = skt.getsockopt(Socket::IPPROTO_TCP, Socket::TCP_INFO)
177
178
  rescue IOError, SystemCallError
178
- Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue
179
+ Puma::Util.purge_interrupt_queue
179
180
  @precheck_closing = false
180
181
  false
181
182
  else
@@ -227,6 +228,7 @@ module Puma
227
228
  @status = :run
228
229
 
229
230
  @thread_pool = ThreadPool.new(
231
+ thread_name,
230
232
  @min_threads,
231
233
  @max_threads,
232
234
  ::Puma::IOBuffer,
@@ -321,6 +323,8 @@ module Puma
321
323
  remote_addr_value = @options[:remote_address_value]
322
324
  when :header
323
325
  remote_addr_header = @options[:remote_address_header]
326
+ when :proxy_protocol
327
+ remote_addr_proxy_protocol = @options[:remote_address_proxy_protocol]
324
328
  end
325
329
 
326
330
  while @status == :run || (drain && shutting_down?)
@@ -341,15 +345,21 @@ module Puma
341
345
  end
342
346
  drain += 1 if shutting_down?
343
347
  client = Client.new io, @binder.env(sock)
348
+ client.listener = sock
344
349
  if remote_addr_value
345
350
  client.peerip = remote_addr_value
346
351
  elsif remote_addr_header
347
352
  client.remote_addr_header = remote_addr_header
353
+ elsif remote_addr_proxy_protocol
354
+ client.expect_proxy_proto = remote_addr_proxy_protocol
348
355
  end
349
356
  pool << client
350
357
  end
351
358
  end
352
- rescue Object => e
359
+ rescue IOError, Errno::EBADF
360
+ # In the case that any of the sockets are unexpectedly close.
361
+ raise
362
+ rescue StandardError => e
353
363
  @events.unknown_error e, nil, "Listen loop"
354
364
  end
355
365
  end
@@ -395,7 +405,7 @@ module Puma
395
405
  return true
396
406
  end
397
407
 
398
- return false
408
+ false
399
409
  end
400
410
 
401
411
  # Given a connection on +client+, handle the incoming requests,
@@ -434,7 +444,7 @@ module Puma
434
444
 
435
445
  while true
436
446
  @requests_count += 1
437
- case handle_request(client, buffer)
447
+ case handle_request(client, buffer, requests + 1)
438
448
  when false
439
449
  break
440
450
  when :async
@@ -447,23 +457,17 @@ module Puma
447
457
 
448
458
  requests += 1
449
459
 
450
- # Closing keepalive sockets after they've made a reasonable
451
- # number of requests allows Puma to service many connections
452
- # fairly, even when the number of concurrent connections exceeds
453
- # the size of the threadpool. It also allows cluster mode Pumas
454
- # to keep load evenly distributed across workers, because clients
455
- # are randomly assigned a new worker when opening a new connection.
456
- #
457
- # Previously, Puma would kick connections in this conditional back
458
- # to the reactor. However, because this causes the todo set to increase
459
- # in size, the wait_until_full mutex would never unlock, leaving
460
- # any additional connections unserviced.
461
- break if requests >= @max_fast_inline
462
-
463
- check_for_more_data = @status == :run
460
+ # As an optimization, try to read the next request from the
461
+ # socket for a short time before returning to the reactor.
462
+ fast_check = @status == :run
463
+
464
+ # Always pass the client back to the reactor after a reasonable
465
+ # number of inline requests if there are other requests pending.
466
+ fast_check = false if requests >= @max_fast_inline &&
467
+ @thread_pool.backlog > 0
464
468
 
465
469
  next_request_ready = with_force_shutdown(client) do
466
- client.reset(check_for_more_data)
470
+ client.reset(fast_check)
467
471
  end
468
472
 
469
473
  unless next_request_ready
@@ -487,7 +491,7 @@ module Puma
487
491
  begin
488
492
  client.close if close_socket
489
493
  rescue IOError, SystemCallError
490
- Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue
494
+ Puma::Util.purge_interrupt_queue
491
495
  # Already closed
492
496
  rescue StandardError => e
493
497
  @events.unknown_error e, nil, "Client"
@@ -579,11 +583,11 @@ module Puma
579
583
  @notify << message
580
584
  rescue IOError, NoMethodError, Errno::EPIPE
581
585
  # The server, in another thread, is shutting down
582
- Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue
586
+ Puma::Util.purge_interrupt_queue
583
587
  rescue RuntimeError => e
584
588
  # Temporary workaround for https://bugs.ruby-lang.org/issues/13239
585
589
  if e.message.include?('IOError')
586
- Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue
590
+ Puma::Util.purge_interrupt_queue
587
591
  else
588
592
  raise e
589
593
  end
@@ -29,7 +29,7 @@ module Puma
29
29
  # The block passed is the work that will be performed in each
30
30
  # thread.
31
31
  #
32
- def initialize(min, max, *extra, &block)
32
+ def initialize(name, min, max, *extra, &block)
33
33
  @not_empty = ConditionVariable.new
34
34
  @not_full = ConditionVariable.new
35
35
  @mutex = Mutex.new
@@ -39,6 +39,7 @@ module Puma
39
39
  @spawned = 0
40
40
  @waiting = 0
41
41
 
42
+ @name = name
42
43
  @min = Integer(min)
43
44
  @max = Integer(max)
44
45
  @block = block
@@ -101,7 +102,7 @@ module Puma
101
102
  @spawned += 1
102
103
 
103
104
  th = Thread.new(@spawned) do |spawned|
104
- Puma.set_thread_name 'threadpool %03i' % spawned
105
+ Puma.set_thread_name '%s threadpool %03i' % [@name, spawned]
105
106
  todo = @todo
106
107
  block = @block
107
108
  mutex = @mutex
@@ -119,6 +120,7 @@ module Puma
119
120
  @trim_requested -= 1
120
121
  @spawned -= 1
121
122
  @workers.delete th
123
+ not_full.signal
122
124
  Thread.exit
123
125
  end
124
126
 
@@ -318,12 +320,12 @@ module Puma
318
320
  end
319
321
 
320
322
  def auto_trim!(timeout=30)
321
- @auto_trim = Automaton.new(self, timeout, "threadpool trimmer", :trim)
323
+ @auto_trim = Automaton.new(self, timeout, "#{@name} threadpool trimmer", :trim)
322
324
  @auto_trim.start!
323
325
  end
324
326
 
325
327
  def auto_reap!(timeout=5)
326
- @reaper = Automaton.new(self, timeout, "threadpool reaper", :reap)
328
+ @reaper = Automaton.new(self, timeout, "#{@name} threadpool reaper", :reap)
327
329
  @reaper.start!
328
330
  end
329
331
 
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)
@@ -61,7 +68,7 @@ module Puma
61
68
  end
62
69
  end
63
70
 
64
- return params
71
+ params
65
72
  end
66
73
 
67
74
  # A case-insensitive Hash that preserves the original case of a
data/lib/puma.rb CHANGED
@@ -12,7 +12,7 @@ require 'thread'
12
12
 
13
13
  require 'puma/puma_http11'
14
14
  require 'puma/detect'
15
- require 'puma/json'
15
+ require 'puma/json_serialization'
16
16
 
17
17
  module Puma
18
18
  autoload :Const, 'puma/const'
@@ -60,7 +60,7 @@ module Puma
60
60
 
61
61
  # @!attribute [rw] stats_object
62
62
  def self.stats
63
- Puma::JSON.generate @get_stats.stats
63
+ Puma::JSONSerialization.generate @get_stats.stats
64
64
  end
65
65
 
66
66
  # @!attribute [r] stats_hash
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.3.1
4
+ version: 5.5.1
5
5
  platform: java
6
6
  authors:
7
7
  - Evan Phoenix
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-11 00:00:00.000000000 Z
11
+ date: 2021-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -24,9 +24,9 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
- description: Puma is a simple, fast, threaded, and highly concurrent HTTP 1.1 server
27
+ description: Puma is a simple, fast, threaded, and highly parallel HTTP 1.1 server
28
28
  for Ruby/Rack applications. Puma is intended for use in both development and production
29
- environments. It's great for highly concurrent Ruby implementations such as Rubinius
29
+ environments. It's great for highly parallel Ruby implementations such as Rubinius
30
30
  and JRuby as well as as providing process worker support to support CRuby well.
31
31
  email:
32
32
  - evan@phx.io
@@ -93,7 +93,7 @@ files:
93
93
  - lib/puma/events.rb
94
94
  - lib/puma/io_buffer.rb
95
95
  - lib/puma/jruby_restart.rb
96
- - lib/puma/json.rb
96
+ - lib/puma/json_serialization.rb
97
97
  - lib/puma/launcher.rb
98
98
  - lib/puma/minissl.rb
99
99
  - lib/puma/minissl/context_builder.rb
@@ -143,6 +143,6 @@ requirements: []
143
143
  rubygems_version: 3.1.6
144
144
  signing_key:
145
145
  specification_version: 4
146
- summary: Puma is a simple, fast, threaded, and highly concurrent HTTP 1.1 server for
146
+ summary: Puma is a simple, fast, threaded, and highly parallel HTTP 1.1 server for
147
147
  Ruby/Rack applications
148
148
  test_files: []