puma 8.0.3 → 8.1.1
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 +125 -0
- data/README.md +28 -378
- data/docs/binding.md +135 -0
- data/docs/cluster_mode.md +241 -0
- data/docs/configuration.md +78 -0
- data/docs/{stats.md → control_server.md} +28 -8
- data/docs/{deployment.md → deployment/README.md} +23 -7
- data/docs/{kubernetes.md → deployment/kubernetes.md} +4 -4
- data/docs/{systemd.md → deployment/systemd.md} +4 -2
- data/docs/plugins.md +62 -3
- data/docs/puma_support.md +92 -0
- data/docs/rails_dev_mode.md +2 -2
- data/docs/restart.md +8 -3
- data/docs/signals.md +4 -2
- data/docs/{5.0-Upgrade.md → upgrading/5.0-Upgrade.md} +3 -3
- data/docs/{6.0-Upgrade.md → upgrading/6.0-Upgrade.md} +3 -3
- data/docs/{7.0-Upgrade.md → upgrading/7.0-Upgrade.md} +2 -2
- data/docs/{8.0-Upgrade.md → upgrading/8.0-Upgrade.md} +4 -4
- data/ext/puma_http11/extconf.rb +2 -0
- data/ext/puma_http11/http11_parser.c +6 -2
- data/ext/puma_http11/mini_ssl.c +8 -4
- data/ext/puma_http11/puma_http11.c +24 -0
- data/lib/puma/binder.rb +29 -0
- data/lib/puma/cli.rb +6 -0
- data/lib/puma/client.rb +75 -29
- data/lib/puma/client_env.rb +32 -18
- data/lib/puma/cluster/worker.rb +109 -33
- data/lib/puma/cluster/worker_handle.rb +16 -0
- data/lib/puma/cluster.rb +173 -45
- data/lib/puma/commonlogger.rb +3 -3
- data/lib/puma/configuration.rb +22 -3
- data/lib/puma/const.rb +11 -9
- data/lib/puma/dsl.rb +265 -91
- data/lib/puma/launcher.rb +6 -4
- data/lib/puma/minissl.rb +2 -5
- data/lib/puma/plugin/systemd.rb +1 -1
- data/lib/puma/response.rb +13 -5
- data/lib/puma/runner.rb +5 -1
- data/lib/puma/sd_notify.rb +4 -1
- data/lib/puma/server.rb +45 -20
- data/lib/puma/thread_pool.rb +12 -1
- data/lib/puma.rb +1 -1
- metadata +18 -30
- data/docs/fork_worker.md +0 -41
- data/docs/grpc.md +0 -62
- data/docs/jungle/README.md +0 -9
- data/docs/testing_benchmarks_local_files.md +0 -150
- data/docs/testing_test_rackup_ci_files.md +0 -36
- data/ext/puma_http11/PumaHttp11Service.java +0 -17
- data/ext/puma_http11/http11_parser.java.rl +0 -131
- data/ext/puma_http11/http11_parser.rl +0 -149
- data/ext/puma_http11/http11_parser_common.rl +0 -54
- data/ext/puma_http11/no_ssl/PumaHttp11Service.java +0 -15
- data/ext/puma_http11/org/jruby/puma/EnvKey.java +0 -241
- data/ext/puma_http11/org/jruby/puma/Http11.java +0 -321
- data/ext/puma_http11/org/jruby/puma/Http11Parser.java +0 -441
- data/ext/puma_http11/org/jruby/puma/MiniSSL.java +0 -519
- data/tools/Dockerfile +0 -26
- data/tools/trickletest.rb +0 -44
- /data/docs/{nginx.md → deployment/nginx.md} +0 -0
- /data/docs/{jungle → deployment}/rc.d/README.md +0 -0
- /data/docs/{jungle → deployment}/rc.d/puma +0 -0
- /data/docs/{jungle → deployment}/rc.d/puma.conf +0 -0
data/lib/puma/cluster.rb
CHANGED
|
@@ -15,6 +15,9 @@ module Puma
|
|
|
15
15
|
# via the `spawn_workers` method call. Each worker will have it's own
|
|
16
16
|
# instance of a `Puma::Server`.
|
|
17
17
|
class Cluster < Runner
|
|
18
|
+
MOLD_FORK_FORMAT = "L"
|
|
19
|
+
MOLD_FORK_BYTES = 4
|
|
20
|
+
|
|
18
21
|
def initialize(launcher)
|
|
19
22
|
super(launcher)
|
|
20
23
|
|
|
@@ -24,6 +27,11 @@ module Puma
|
|
|
24
27
|
|
|
25
28
|
@worker_max = [] # keeps track of 'max' stat values
|
|
26
29
|
@pending_phased_restart = false
|
|
30
|
+
@promoted_mold = nil
|
|
31
|
+
@mold = nil
|
|
32
|
+
@retired_molds = []
|
|
33
|
+
@mold_ready = false
|
|
34
|
+
@mold_threshold_index = 0
|
|
27
35
|
end
|
|
28
36
|
|
|
29
37
|
# Returns the list of cluster worker handles.
|
|
@@ -32,12 +40,12 @@ module Puma
|
|
|
32
40
|
|
|
33
41
|
def stop_workers
|
|
34
42
|
log "- Gracefully shutting down workers..."
|
|
35
|
-
@workers.each { |x| x.term }
|
|
43
|
+
(@workers + molds).each { |x| x.term }
|
|
36
44
|
|
|
37
45
|
begin
|
|
38
46
|
loop do
|
|
39
47
|
wait_workers
|
|
40
|
-
break if @workers.reject {|w| w.pid.nil?}.empty?
|
|
48
|
+
break if @workers.reject {|w| w.pid.nil?}.empty? && molds.empty?
|
|
41
49
|
sleep 0.2
|
|
42
50
|
end
|
|
43
51
|
rescue Interrupt
|
|
@@ -69,7 +77,7 @@ module Puma
|
|
|
69
77
|
|
|
70
78
|
def spawn_workers
|
|
71
79
|
diff = @options[:workers] - @workers.size
|
|
72
|
-
return if diff < 1
|
|
80
|
+
return if diff < 1 || @promoted_mold
|
|
73
81
|
|
|
74
82
|
master = Process.pid
|
|
75
83
|
if @options[:fork_worker]
|
|
@@ -82,6 +90,9 @@ module Puma
|
|
|
82
90
|
if @options[:fork_worker] && idx != 0
|
|
83
91
|
@fork_writer << "#{idx}\n"
|
|
84
92
|
pid = nil
|
|
93
|
+
elsif @mold
|
|
94
|
+
@fork_writer << [idx].pack(MOLD_FORK_FORMAT)
|
|
95
|
+
pid = nil
|
|
85
96
|
else
|
|
86
97
|
pid = spawn_worker(idx, master)
|
|
87
98
|
end
|
|
@@ -168,6 +179,8 @@ module Puma
|
|
|
168
179
|
end
|
|
169
180
|
|
|
170
181
|
def all_workers_idle_timed_out?
|
|
182
|
+
return false if @pending_phased_restart || @workers.empty?
|
|
183
|
+
|
|
171
184
|
(@workers.map(&:pid) - idle_timed_out_worker_pids).empty?
|
|
172
185
|
end
|
|
173
186
|
|
|
@@ -206,6 +219,10 @@ module Puma
|
|
|
206
219
|
t.map!(&:ping_timeout)
|
|
207
220
|
|
|
208
221
|
@next_check = [t.min, @next_check].compact.min
|
|
222
|
+
if @options[:fork_worker] && @workers.any?(&:term?)
|
|
223
|
+
# Orphaned workers cannot wake the master through worker 0 as they exit.
|
|
224
|
+
@next_check = [@next_check, Time.now + 0.1].min
|
|
225
|
+
end
|
|
209
226
|
end
|
|
210
227
|
|
|
211
228
|
def worker(index, master)
|
|
@@ -216,7 +233,7 @@ module Puma
|
|
|
216
233
|
@fork_writer.close
|
|
217
234
|
|
|
218
235
|
pipes = { check_pipe: @check_pipe, worker_write: @worker_write }
|
|
219
|
-
if
|
|
236
|
+
if refork?
|
|
220
237
|
pipes[:fork_pipe] = @fork_pipe
|
|
221
238
|
pipes[:wakeup] = @wakeup
|
|
222
239
|
end
|
|
@@ -252,7 +269,6 @@ module Puma
|
|
|
252
269
|
@status = :stop if @status == :run
|
|
253
270
|
wakeup!
|
|
254
271
|
@control&.stop true
|
|
255
|
-
Process.waitall
|
|
256
272
|
end
|
|
257
273
|
|
|
258
274
|
def halt
|
|
@@ -299,14 +315,22 @@ module Puma
|
|
|
299
315
|
@options[:preload_app]
|
|
300
316
|
end
|
|
301
317
|
|
|
318
|
+
def refork?
|
|
319
|
+
@options[:fork_worker] || @options[:mold_worker]
|
|
320
|
+
end
|
|
321
|
+
|
|
302
322
|
# @version 5.0.0
|
|
303
323
|
def fork_worker!
|
|
304
324
|
if (worker = worker_at 0)
|
|
305
|
-
worker.phase
|
|
325
|
+
worker.phase = @phase + 1
|
|
306
326
|
end
|
|
307
327
|
phased_restart(true)
|
|
308
328
|
end
|
|
309
329
|
|
|
330
|
+
def mold_worker!
|
|
331
|
+
phased_restart(true)
|
|
332
|
+
end
|
|
333
|
+
|
|
310
334
|
# We do this in a separate method to keep the lambda scope
|
|
311
335
|
# of the signals handlers as small as possible.
|
|
312
336
|
def setup_signals
|
|
@@ -325,6 +349,24 @@ module Puma
|
|
|
325
349
|
end
|
|
326
350
|
end
|
|
327
351
|
|
|
352
|
+
if @options[:mold_worker]
|
|
353
|
+
Signal.trap "SIGURG" do
|
|
354
|
+
mold_worker!
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
@events.register(:ping!) do |w|
|
|
358
|
+
threshold = @options[:mold_worker][@mold_threshold_index]
|
|
359
|
+
next unless threshold &&
|
|
360
|
+
!w.mold? &&
|
|
361
|
+
!@pending_phased_restart &&
|
|
362
|
+
w.last_status[:requests_count] >= threshold &&
|
|
363
|
+
all_workers_in_phase?
|
|
364
|
+
|
|
365
|
+
@mold_threshold_index += 1
|
|
366
|
+
mold_worker!
|
|
367
|
+
end
|
|
368
|
+
end
|
|
369
|
+
|
|
328
370
|
Signal.trap "SIGCHLD" do
|
|
329
371
|
wakeup!
|
|
330
372
|
end
|
|
@@ -375,7 +417,7 @@ module Puma
|
|
|
375
417
|
|
|
376
418
|
before = Thread.list.reject(&fork_safe)
|
|
377
419
|
|
|
378
|
-
log "* Restarts: (\u2714) hot (\u2716) phased (#{
|
|
420
|
+
log "* Restarts: (\u2714) hot (\u2716) phased (#{refork? ? "\u2714" : "\u2716"}) refork"
|
|
379
421
|
log "* Preloading application"
|
|
380
422
|
load_and_bind
|
|
381
423
|
|
|
@@ -393,7 +435,7 @@ module Puma
|
|
|
393
435
|
end
|
|
394
436
|
end
|
|
395
437
|
else
|
|
396
|
-
log "* Restarts: (\u2714) hot (\u2714) phased (#{
|
|
438
|
+
log "* Restarts: (\u2714) hot (\u2714) phased (#{refork? ? "\u2714" : "\u2716"}) refork"
|
|
397
439
|
|
|
398
440
|
unless @config.app_configured?
|
|
399
441
|
error "No application configured, nothing to run"
|
|
@@ -437,6 +479,9 @@ module Puma
|
|
|
437
479
|
|
|
438
480
|
@config.run_hooks(:before_fork, nil, @log_writer)
|
|
439
481
|
|
|
482
|
+
# Reparent workers to the master if their mold exits.
|
|
483
|
+
Puma.enable_child_subreaper if @options[:mold_worker]
|
|
484
|
+
|
|
440
485
|
spawn_workers
|
|
441
486
|
|
|
442
487
|
Signal.trap "SIGINT" do
|
|
@@ -446,7 +491,6 @@ module Puma
|
|
|
446
491
|
begin
|
|
447
492
|
booted = false
|
|
448
493
|
in_phased_restart = false
|
|
449
|
-
workers_not_booted = @options[:workers]
|
|
450
494
|
|
|
451
495
|
while @status == :run
|
|
452
496
|
begin
|
|
@@ -455,15 +499,11 @@ module Puma
|
|
|
455
499
|
break
|
|
456
500
|
end
|
|
457
501
|
|
|
458
|
-
if @pending_phased_restart
|
|
502
|
+
if @pending_phased_restart && prepare_phased_restart
|
|
459
503
|
start_phased_restart(@pending_phased_restart == :refork)
|
|
460
504
|
|
|
461
505
|
in_phased_restart = @pending_phased_restart
|
|
462
506
|
@pending_phased_restart = false
|
|
463
|
-
|
|
464
|
-
workers_not_booted = @options[:workers]
|
|
465
|
-
# worker 0 is not restarted on refork
|
|
466
|
-
workers_not_booted -= 1 if in_phased_restart == :refork
|
|
467
507
|
end
|
|
468
508
|
|
|
469
509
|
check_workers(in_phased_restart == :refork)
|
|
@@ -479,20 +519,28 @@ module Puma
|
|
|
479
519
|
|
|
480
520
|
result = read.gets
|
|
481
521
|
pid = result.to_i
|
|
522
|
+
w = (@workers + molds).find { |x| x.pid == pid }
|
|
482
523
|
|
|
483
|
-
if req == PIPE_BOOT || req == PIPE_FORK
|
|
524
|
+
if !w && (req == PIPE_BOOT || req == PIPE_FORK)
|
|
484
525
|
pid, idx = result.split(':').map(&:to_i)
|
|
485
526
|
w = worker_at idx
|
|
486
|
-
w
|
|
527
|
+
if w && w.pid.nil?
|
|
528
|
+
w.pid = pid
|
|
529
|
+
else
|
|
530
|
+
w = nil
|
|
531
|
+
begin
|
|
532
|
+
Process.kill "KILL", pid
|
|
533
|
+
rescue Errno::ESRCH
|
|
534
|
+
end
|
|
535
|
+
end
|
|
487
536
|
end
|
|
488
537
|
|
|
489
|
-
if w
|
|
538
|
+
if w
|
|
490
539
|
case req
|
|
491
540
|
when PIPE_BOOT
|
|
492
541
|
w.boot!
|
|
493
542
|
log "- Worker #{w.index} (PID: #{pid}) booted in #{w.uptime.round(2)}s, phase: #{w.phase}"
|
|
494
543
|
@next_check = Time.now
|
|
495
|
-
workers_not_booted -= 1
|
|
496
544
|
when PIPE_EXTERNAL_TERM
|
|
497
545
|
# external term, see worker method, Signal.trap "SIGTERM"
|
|
498
546
|
w.term!
|
|
@@ -503,7 +551,7 @@ module Puma
|
|
|
503
551
|
w.ping!(status)
|
|
504
552
|
@events.fire(:ping!, w)
|
|
505
553
|
|
|
506
|
-
if in_phased_restart && @options[:fork_worker] &&
|
|
554
|
+
if in_phased_restart && @options[:fork_worker] && w0 = worker_at(0)
|
|
507
555
|
w0.ping!(status)
|
|
508
556
|
@events.fire(:ping!, w0)
|
|
509
557
|
end
|
|
@@ -519,13 +567,17 @@ module Puma
|
|
|
519
567
|
else
|
|
520
568
|
idle_workers[pid] = true
|
|
521
569
|
end
|
|
570
|
+
when PIPE_MOLD
|
|
571
|
+
activate_mold(w)
|
|
572
|
+
@next_check = Time.now
|
|
522
573
|
end
|
|
523
574
|
else
|
|
524
575
|
log "! Out-of-sync worker list, no #{pid} worker"
|
|
525
576
|
end
|
|
526
577
|
end
|
|
527
578
|
|
|
528
|
-
if in_phased_restart &&
|
|
579
|
+
if in_phased_restart && @workers.size == @options[:workers] && all_workers_booted? && all_workers_in_phase?
|
|
580
|
+
@retired_molds.each(&:term)
|
|
529
581
|
@events.fire_after_booted!
|
|
530
582
|
debug_loaded_extensions("Loaded Extensions - master:") if @log_writer.debug?
|
|
531
583
|
in_phased_restart = false
|
|
@@ -574,43 +626,119 @@ module Puma
|
|
|
574
626
|
end
|
|
575
627
|
end
|
|
576
628
|
|
|
629
|
+
fork_worker_exited = false
|
|
577
630
|
@workers.reject! do |w|
|
|
578
|
-
next
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
if (status = reaped_children.delete(w.pid) || Process.wait2(w.pid, Process::WNOHANG)&.last)
|
|
586
|
-
w.process_status = status
|
|
587
|
-
@config.run_hooks(:after_worker_shutdown, w, @log_writer)
|
|
588
|
-
true
|
|
589
|
-
else
|
|
590
|
-
w.term if w.term?
|
|
591
|
-
nil
|
|
592
|
-
end
|
|
593
|
-
rescue Errno::ECHILD
|
|
594
|
-
begin
|
|
595
|
-
Process.kill(0, w.pid)
|
|
596
|
-
# child still alive but has another parent (e.g., using fork_worker)
|
|
597
|
-
w.term if w.term?
|
|
598
|
-
false
|
|
599
|
-
rescue Errno::ESRCH, Errno::EPERM
|
|
600
|
-
true # child is already terminated
|
|
601
|
-
end
|
|
631
|
+
next w.term? if w.pid.nil?
|
|
632
|
+
|
|
633
|
+
status = reap(w, reaped_children)
|
|
634
|
+
fork_worker_exited = true if status && @options[:fork_worker] && w.index == 0
|
|
635
|
+
if status.is_a?(Process::Status)
|
|
636
|
+
w.process_status = status
|
|
637
|
+
@config.run_hooks(:after_worker_shutdown, w, @log_writer)
|
|
602
638
|
end
|
|
639
|
+
status
|
|
603
640
|
end
|
|
604
641
|
|
|
642
|
+
clear_pending_workers if fork_worker_exited
|
|
643
|
+
@promoted_mold = nil if @promoted_mold && reap(@promoted_mold, reaped_children)
|
|
644
|
+
if @mold && reap(@mold, reaped_children)
|
|
645
|
+
@mold = nil
|
|
646
|
+
clear_pending_workers
|
|
647
|
+
end
|
|
648
|
+
@retired_molds.reject! { |m| reap(m, reaped_children) }
|
|
649
|
+
|
|
605
650
|
# Log unknown children
|
|
606
651
|
reaped_children.each do |pid, status|
|
|
607
652
|
log "! reaped unknown child process pid=#{pid} status=#{status}"
|
|
608
653
|
end
|
|
609
654
|
end
|
|
610
655
|
|
|
656
|
+
def clear_pending_workers
|
|
657
|
+
@workers.reject! { |w| w.pid.nil? }
|
|
658
|
+
while @fork_pipe.read_nonblock(4096, exception: false).is_a?(String)
|
|
659
|
+
end
|
|
660
|
+
end
|
|
661
|
+
|
|
662
|
+
# Returns the process status once the process has exited, true if it has
|
|
663
|
+
# exited but its status cannot be collected, or nil if it is still running.
|
|
664
|
+
def reap(handle, reaped_children)
|
|
665
|
+
# We may need to check the PID individually because:
|
|
666
|
+
# 1. From Ruby versions 2.6 to 3.2, `Process.detach` can prevent or delay
|
|
667
|
+
# `Process.wait2(-1)` from detecting a terminated process: https://bugs.ruby-lang.org/issues/19837.
|
|
668
|
+
# 2. When `fork_worker` or `mold_worker` is enabled, some workers may not be direct children,
|
|
669
|
+
# but grandchildren. Because of this they won't be reaped by `Process.wait2(-1)`.
|
|
670
|
+
status = reaped_children.delete(handle.pid) || Process.wait2(handle.pid, Process::WNOHANG)&.last
|
|
671
|
+
handle.term if !status && handle.term?
|
|
672
|
+
status
|
|
673
|
+
rescue Errno::ECHILD
|
|
674
|
+
begin
|
|
675
|
+
Process.kill(0, handle.pid)
|
|
676
|
+
# child still alive but has another parent (e.g., using fork_worker)
|
|
677
|
+
handle.term if handle.term?
|
|
678
|
+
nil
|
|
679
|
+
rescue Errno::ESRCH, Errno::EPERM
|
|
680
|
+
true # child is already terminated
|
|
681
|
+
end
|
|
682
|
+
end
|
|
683
|
+
|
|
684
|
+
def molds
|
|
685
|
+
[@promoted_mold, @mold, *@retired_molds].compact
|
|
686
|
+
end
|
|
687
|
+
|
|
688
|
+
# Returns true once workers can be restarted. With `mold_worker`, a refork
|
|
689
|
+
# first promotes a new mold and waits for it, while a phased restart
|
|
690
|
+
# retires all molds so workers are forked from the master.
|
|
691
|
+
def prepare_phased_restart
|
|
692
|
+
return true unless @options[:mold_worker]
|
|
693
|
+
|
|
694
|
+
if @pending_phased_restart != :refork
|
|
695
|
+
retire_molds
|
|
696
|
+
@mold_ready = false
|
|
697
|
+
@mold_threshold_index = 0
|
|
698
|
+
true
|
|
699
|
+
elsif @mold_ready
|
|
700
|
+
@mold_ready = false
|
|
701
|
+
true
|
|
702
|
+
else
|
|
703
|
+
promote_mold unless @promoted_mold
|
|
704
|
+
false
|
|
705
|
+
end
|
|
706
|
+
end
|
|
707
|
+
|
|
708
|
+
def promote_mold
|
|
709
|
+
candidate = @workers.select { |w| w.booted? && !w.term? }
|
|
710
|
+
.max_by { |w| w.last_status[:requests_count].to_i }
|
|
711
|
+
return unless candidate
|
|
712
|
+
|
|
713
|
+
log "- Promoting worker #{candidate.index} (PID: #{candidate.pid}) to mold"
|
|
714
|
+
@workers.delete candidate
|
|
715
|
+
@promoted_mold = candidate
|
|
716
|
+
candidate.mold!
|
|
717
|
+
end
|
|
718
|
+
|
|
719
|
+
def activate_mold(mold)
|
|
720
|
+
return unless mold == @promoted_mold
|
|
721
|
+
|
|
722
|
+
log "- Mold (PID: #{mold.pid}) ready"
|
|
723
|
+
@promoted_mold = nil
|
|
724
|
+
retire_molds
|
|
725
|
+
@mold = mold
|
|
726
|
+
@mold_ready = true
|
|
727
|
+
end
|
|
728
|
+
|
|
729
|
+
# A promoted mold has forked no workers, so it is stopped now. An active
|
|
730
|
+
# mold stops forking, and is stopped once the restart completes.
|
|
731
|
+
def retire_molds
|
|
732
|
+
@promoted_mold&.term
|
|
733
|
+
@mold&.retire!
|
|
734
|
+
@retired_molds.concat [@promoted_mold, @mold].compact
|
|
735
|
+
@promoted_mold = nil
|
|
736
|
+
@mold = nil
|
|
737
|
+
end
|
|
738
|
+
|
|
611
739
|
# @version 5.0.0
|
|
612
740
|
def timeout_workers
|
|
613
|
-
@workers.each do |w|
|
|
741
|
+
(@workers + molds).each do |w|
|
|
614
742
|
if !w.term? && w.ping_timeout <= Time.now
|
|
615
743
|
details = if w.booted?
|
|
616
744
|
"(Worker #{w.index} failed to check in within #{@options[:worker_timeout]} seconds)"
|
data/lib/puma/commonlogger.rb
CHANGED
|
@@ -73,7 +73,7 @@ module Puma
|
|
|
73
73
|
env[SERVER_PROTOCOL],
|
|
74
74
|
now - began_at ]
|
|
75
75
|
|
|
76
|
-
write(msg)
|
|
76
|
+
write(env, msg)
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
def log(env, status, header, began_at)
|
|
@@ -92,10 +92,10 @@ module Puma
|
|
|
92
92
|
length,
|
|
93
93
|
now - began_at ]
|
|
94
94
|
|
|
95
|
-
write(msg)
|
|
95
|
+
write(env, msg)
|
|
96
96
|
end
|
|
97
97
|
|
|
98
|
-
def write(msg)
|
|
98
|
+
def write(env, msg)
|
|
99
99
|
logger = @logger || env['rack.errors']
|
|
100
100
|
|
|
101
101
|
# Standard library logger doesn't support write but it supports << which actually
|
data/lib/puma/configuration.rb
CHANGED
|
@@ -133,6 +133,7 @@ module Puma
|
|
|
133
133
|
class NotClampedError < StandardError; end
|
|
134
134
|
|
|
135
135
|
DEFAULTS = {
|
|
136
|
+
allow_underscore_headers: true,
|
|
136
137
|
auto_trim_time: 30,
|
|
137
138
|
binds: ['tcp://[::]:9292'.freeze],
|
|
138
139
|
debug: false,
|
|
@@ -284,11 +285,17 @@ module Puma
|
|
|
284
285
|
#
|
|
285
286
|
# This also calls load if it hasn't been called yet.
|
|
286
287
|
def clamp
|
|
288
|
+
if @clamped
|
|
289
|
+
warn "Configuration already clamped, calling clamp multiple times is deprecated and will raise in Puma v9"
|
|
290
|
+
return options
|
|
291
|
+
end
|
|
292
|
+
|
|
287
293
|
load unless @loaded
|
|
288
294
|
run_mode_hooks
|
|
289
295
|
set_conditional_default_options
|
|
290
296
|
@_options.finalize_values
|
|
291
297
|
rewrite_unavailable_ipv6_binds!
|
|
298
|
+
validate_options
|
|
292
299
|
@clamped = true
|
|
293
300
|
warn_hooks
|
|
294
301
|
options
|
|
@@ -357,8 +364,7 @@ module Puma
|
|
|
357
364
|
block.call arg
|
|
358
365
|
end
|
|
359
366
|
rescue => e
|
|
360
|
-
|
|
361
|
-
log_writer.debug e.backtrace.join("\n")
|
|
367
|
+
handle_hook_error e, key, log_writer
|
|
362
368
|
end
|
|
363
369
|
end
|
|
364
370
|
end
|
|
@@ -399,6 +405,15 @@ module Puma
|
|
|
399
405
|
|
|
400
406
|
private
|
|
401
407
|
|
|
408
|
+
def handle_hook_error(e, key, log_writer)
|
|
409
|
+
if (handler = options[:hook_error_handler])
|
|
410
|
+
handler.call(e, key)
|
|
411
|
+
else
|
|
412
|
+
log_writer.log "WARNING hook #{key} failed with exception (#{e.class}) #{e.message}"
|
|
413
|
+
log_writer.debug e.backtrace.join("\n")
|
|
414
|
+
end
|
|
415
|
+
end
|
|
416
|
+
|
|
402
417
|
def rewrite_unavailable_ipv6_binds!
|
|
403
418
|
return if self.class.ipv6_interface_available?
|
|
404
419
|
|
|
@@ -492,7 +507,7 @@ module Puma
|
|
|
492
507
|
@_options.all_of(key).each(&:call)
|
|
493
508
|
|
|
494
509
|
unless @_options[:workers] == workers_before
|
|
495
|
-
raise "
|
|
510
|
+
raise "Cannot change the number of workers inside a #{key} configuration hook"
|
|
496
511
|
end
|
|
497
512
|
end
|
|
498
513
|
|
|
@@ -501,6 +516,10 @@ module Puma
|
|
|
501
516
|
(@_options[:workers] > 1) && Puma.forkable?
|
|
502
517
|
end
|
|
503
518
|
|
|
519
|
+
def validate_options
|
|
520
|
+
raise "fork_worker and mold_worker cannot be used together" if @_options[:fork_worker] && @_options[:mold_worker]
|
|
521
|
+
end
|
|
522
|
+
|
|
504
523
|
def warn_hooks
|
|
505
524
|
return if options[:workers] > 0
|
|
506
525
|
return if options[:silence_fork_callback_warning]
|
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 = "8.
|
|
104
|
-
CODE_NAME = "
|
|
103
|
+
PUMA_VERSION = VERSION = "8.1.1"
|
|
104
|
+
CODE_NAME = "Puma Psychosis"
|
|
105
105
|
|
|
106
106
|
PUMA_SERVER_STRING = ["puma", PUMA_VERSION, CODE_NAME].join(" ").freeze
|
|
107
107
|
|
|
@@ -150,12 +150,12 @@ module Puma
|
|
|
150
150
|
REQUEST_METHOD = "REQUEST_METHOD"
|
|
151
151
|
HEAD = "HEAD"
|
|
152
152
|
|
|
153
|
-
# based on https://www.rfc-editor.org/rfc/rfc9110.html#name-overview,
|
|
154
|
-
# with CONNECT removed, and PATCH added
|
|
155
|
-
SUPPORTED_HTTP_METHODS = %w[HEAD GET POST PUT DELETE OPTIONS TRACE PATCH].freeze
|
|
153
|
+
# based on https://www.rfc-editor.org/rfc/rfc9110.html#name-overview and https://www.rfc-editor.org/rfc/rfc10008.html,
|
|
154
|
+
# with CONNECT removed, and PATCH & QUERY added
|
|
155
|
+
SUPPORTED_HTTP_METHODS = %w[HEAD GET POST PUT DELETE OPTIONS TRACE PATCH QUERY].freeze
|
|
156
156
|
|
|
157
157
|
# list from https://www.iana.org/assignments/http-methods/http-methods.xhtml
|
|
158
|
-
# as of
|
|
158
|
+
# as of 17-Jun-26, with QUERY added based on https://www.rfc-editor.org/rfc/rfc10008.html
|
|
159
159
|
IANA_HTTP_METHODS = %w[
|
|
160
160
|
ACL
|
|
161
161
|
BASELINE-CONTROL
|
|
@@ -185,6 +185,7 @@ module Puma
|
|
|
185
185
|
PROPFIND
|
|
186
186
|
PROPPATCH
|
|
187
187
|
PUT
|
|
188
|
+
QUERY
|
|
188
189
|
REBIND
|
|
189
190
|
REPORT
|
|
190
191
|
SEARCH
|
|
@@ -235,6 +236,7 @@ module Puma
|
|
|
235
236
|
PUMA_SOCKET = "puma.socket"
|
|
236
237
|
PUMA_CONFIG = "puma.config"
|
|
237
238
|
PUMA_PEERCERT = "puma.peercert"
|
|
239
|
+
PUMA_UNDERSCORE_HEADERS = "puma.underscore_headers"
|
|
238
240
|
|
|
239
241
|
HTTP = "http"
|
|
240
242
|
HTTPS = "https"
|
|
@@ -283,9 +285,8 @@ module Puma
|
|
|
283
285
|
# header values can contain HTAB?
|
|
284
286
|
ILLEGAL_HEADER_VALUE_REGEX = /[\x00-\x08\x0A-\x1F]/.freeze
|
|
285
287
|
|
|
286
|
-
#
|
|
287
|
-
#
|
|
288
|
-
# but if we normalize them after reading, it's just confusing for the application.
|
|
288
|
+
# Framing aliases must never be normalized into standard header keys.
|
|
289
|
+
# Client#setup_body rejects requests containing these keys before body reads.
|
|
289
290
|
UNMASKABLE_HEADERS = {
|
|
290
291
|
"HTTP_TRANSFER,ENCODING" => true,
|
|
291
292
|
"HTTP_CONTENT,LENGTH" => true,
|
|
@@ -306,6 +307,7 @@ module Puma
|
|
|
306
307
|
PIPE_TERM = "t"
|
|
307
308
|
PIPE_PING = "p"
|
|
308
309
|
PIPE_IDLE = "i"
|
|
310
|
+
PIPE_MOLD = "m"
|
|
309
311
|
end
|
|
310
312
|
end
|
|
311
313
|
end
|