puma 8.0.2 → 8.1.2
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 +154 -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 +18 -7
- data/ext/puma_http11/puma_http11.c +28 -3
- data/lib/puma/binder.rb +29 -0
- data/lib/puma/cli.rb +6 -0
- data/lib/puma/client.rb +178 -44
- 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 +23 -3
- data/lib/puma/const.rb +14 -9
- data/lib/puma/control_cli.rb +14 -3
- data/lib/puma/dsl.rb +279 -92
- data/lib/puma/launcher.rb +6 -4
- data/lib/puma/minissl.rb +98 -56
- data/lib/puma/plugin/systemd.rb +1 -1
- data/lib/puma/reactor.rb +35 -3
- data/lib/puma/response.rb +28 -6
- data/lib/puma/runner.rb +5 -1
- data/lib/puma/sd_notify.rb +4 -1
- data/lib/puma/server.rb +131 -35
- data/lib/puma/thread_pool.rb +12 -1
- data/lib/puma/util.rb +8 -4
- data/lib/puma.rb +1 -1
- metadata +19 -31
- 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 -509
- 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/server.rb
CHANGED
|
@@ -51,7 +51,7 @@ module Puma
|
|
|
51
51
|
# @todo the following may be deprecated in the future
|
|
52
52
|
attr_reader :auto_trim_time, :early_hints, :first_data_timeout,
|
|
53
53
|
:leak_stack_on_error,
|
|
54
|
-
:persistent_timeout, :reaping_time
|
|
54
|
+
:persistent_timeout, :reaping_time, :shutdown_body_timeout
|
|
55
55
|
|
|
56
56
|
attr_accessor :app
|
|
57
57
|
attr_accessor :binder
|
|
@@ -98,6 +98,8 @@ module Puma
|
|
|
98
98
|
@early_hints = @options[:early_hints]
|
|
99
99
|
@first_data_timeout = @options[:first_data_timeout]
|
|
100
100
|
@persistent_timeout = @options[:persistent_timeout]
|
|
101
|
+
@shutdown_body_timeout = @options[:shutdown_body_timeout]
|
|
102
|
+
@shutdown_body_deadline = nil
|
|
101
103
|
@idle_timeout = @options[:idle_timeout]
|
|
102
104
|
@min_threads = @options[:min_threads]
|
|
103
105
|
@max_threads = @options[:max_threads]
|
|
@@ -107,6 +109,8 @@ module Puma
|
|
|
107
109
|
@enable_keep_alives &&= @queue_requests
|
|
108
110
|
@io_selector_backend = @options[:io_selector_backend]
|
|
109
111
|
@http_content_length_limit = @options[:http_content_length_limit]
|
|
112
|
+
@continue_callback = @options[:continue_callback]
|
|
113
|
+
@allow_underscore_headers = @options.fetch(:allow_underscore_headers, true)
|
|
110
114
|
@cluster_accept_loop_delay = ClusterAcceptLoopDelay.new(
|
|
111
115
|
workers: @options[:workers],
|
|
112
116
|
max_delay: @options[:wait_for_less_busy_worker] || 0 # Real default is in Configuration::DEFAULTS, this is for unit testing
|
|
@@ -258,6 +262,7 @@ module Puma
|
|
|
258
262
|
@events.fire :state, :booting
|
|
259
263
|
|
|
260
264
|
@status = :run
|
|
265
|
+
@shutdown_body_deadline = nil
|
|
261
266
|
|
|
262
267
|
@thread_pool = ThreadPool.new(thread_name, options, server: self) do |processor, client|
|
|
263
268
|
process_client(processor, client)
|
|
@@ -312,6 +317,9 @@ module Puma
|
|
|
312
317
|
# If a client object times out, a 408 response is written, its connection is closed,
|
|
313
318
|
# and the object is removed from the reactor (return `true`).
|
|
314
319
|
#
|
|
320
|
+
# If the request cannot be read, the Client is passed to the ThreadPool with its
|
|
321
|
+
# `reactor_error` set, so that a processor thread writes the error response.
|
|
322
|
+
#
|
|
315
323
|
# If the Reactor is shutting down, all Clients are either timed out or passed to the
|
|
316
324
|
# ThreadPool, depending on their current state (#can_close?).
|
|
317
325
|
#
|
|
@@ -320,18 +328,33 @@ module Puma
|
|
|
320
328
|
# will wake up and again be checked to see if it's ready to be passed to the thread pool.
|
|
321
329
|
def reactor_wakeup(client)
|
|
322
330
|
shutdown = !@queue_requests
|
|
323
|
-
|
|
324
|
-
|
|
331
|
+
read = client.bytes_read
|
|
332
|
+
if client.try_to_finish { shutdown_body_limit } || (shutdown && !client.can_close?)
|
|
333
|
+
hand_to_thread_pool client
|
|
325
334
|
elsif shutdown || client.timeout == 0
|
|
326
335
|
client.timeout!
|
|
327
336
|
else
|
|
328
|
-
client.set_timeout(@first_data_timeout)
|
|
337
|
+
client.set_timeout(@first_data_timeout) if client.bytes_read > read
|
|
329
338
|
false
|
|
330
339
|
end
|
|
331
|
-
rescue
|
|
332
|
-
client_error(e, client)
|
|
340
|
+
rescue ConnectionError, EOFError
|
|
333
341
|
close_client_safely(client)
|
|
334
342
|
true
|
|
343
|
+
rescue StandardError => e
|
|
344
|
+
# Writing the error response may block on a client that is not reading,
|
|
345
|
+
# so leave it to a thread pool thread.
|
|
346
|
+
client.reactor_error = e
|
|
347
|
+
hand_to_thread_pool client
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
def hand_to_thread_pool(client)
|
|
351
|
+
@thread_pool << client
|
|
352
|
+
true
|
|
353
|
+
rescue ThreadError
|
|
354
|
+
true
|
|
355
|
+
rescue StandardError
|
|
356
|
+
close_client_safely client
|
|
357
|
+
true
|
|
335
358
|
end
|
|
336
359
|
|
|
337
360
|
def handle_servers
|
|
@@ -361,13 +384,16 @@ module Puma
|
|
|
361
384
|
ios = IO.select sockets, nil, nil, (shutting_down? ? 0 : @idle_timeout)
|
|
362
385
|
unless ios
|
|
363
386
|
unless shutting_down?
|
|
364
|
-
@idle_timeout_reached = true
|
|
365
|
-
|
|
366
387
|
if @clustered
|
|
367
|
-
@
|
|
388
|
+
unless @idle_timeout_reached
|
|
389
|
+
@idle_timeout_reached = true
|
|
390
|
+
@worker_write << "#{PipeRequest::PIPE_IDLE}#{Process.pid}\n" rescue nil
|
|
391
|
+
end
|
|
368
392
|
next
|
|
369
393
|
else
|
|
394
|
+
@idle_timeout_reached = true
|
|
370
395
|
@log_writer.log "- Idle timeout reached"
|
|
396
|
+
shutdown_body_deadline
|
|
371
397
|
@status = :stop
|
|
372
398
|
end
|
|
373
399
|
end
|
|
@@ -388,19 +414,30 @@ module Puma
|
|
|
388
414
|
# clients until the code is finished.
|
|
389
415
|
pool.wait_while_out_of_band_running
|
|
390
416
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
417
|
+
unless shutting_down?
|
|
418
|
+
if @queue_requests
|
|
419
|
+
if @cluster_accept_loop_delay.on? && (busy_threads_plus_todo = pool.busy_threads) > 0
|
|
420
|
+
delay = @cluster_accept_loop_delay.calculate(
|
|
421
|
+
max_threads: @max_threads,
|
|
422
|
+
busy_threads_plus_todo: busy_threads_plus_todo
|
|
423
|
+
)
|
|
424
|
+
sleep(delay)
|
|
425
|
+
end
|
|
426
|
+
else
|
|
427
|
+
pool.wait_until_not_full
|
|
428
|
+
|
|
429
|
+
# A stop may have arrived while waiting for a thread
|
|
430
|
+
break if check.wait_readable(0) && handle_check
|
|
431
|
+
end
|
|
398
432
|
end
|
|
399
433
|
|
|
400
434
|
io = begin
|
|
401
435
|
sock.accept_nonblock
|
|
402
436
|
rescue IO::WaitReadable
|
|
403
437
|
next
|
|
438
|
+
rescue Errno::EMFILE, Errno::ENFILE, Errno::ENOBUFS, Errno::ENOMEM => e
|
|
439
|
+
accept_resource_error e
|
|
440
|
+
next
|
|
404
441
|
end
|
|
405
442
|
drain += 1 if shutting_down?
|
|
406
443
|
|
|
@@ -413,11 +450,17 @@ module Puma
|
|
|
413
450
|
# In the case that any of the sockets are unexpectedly close.
|
|
414
451
|
raise
|
|
415
452
|
rescue StandardError => e
|
|
416
|
-
|
|
453
|
+
begin
|
|
454
|
+
@log_writer.unknown_error e, nil, "Listen loop"
|
|
455
|
+
rescue StandardError
|
|
456
|
+
end
|
|
417
457
|
end
|
|
418
458
|
end
|
|
419
459
|
|
|
420
|
-
|
|
460
|
+
begin
|
|
461
|
+
@log_writer.debug { "Drained #{drain} additional connections." } if drain
|
|
462
|
+
rescue StandardError
|
|
463
|
+
end
|
|
421
464
|
@events.fire :state, @status
|
|
422
465
|
|
|
423
466
|
if queue_requests
|
|
@@ -427,7 +470,10 @@ module Puma
|
|
|
427
470
|
|
|
428
471
|
graceful_shutdown if @status == :stop || @status == :restart
|
|
429
472
|
rescue Exception => e
|
|
430
|
-
|
|
473
|
+
begin
|
|
474
|
+
@log_writer.unknown_error e, nil, "Exception handling servers"
|
|
475
|
+
rescue StandardError
|
|
476
|
+
end
|
|
431
477
|
ensure
|
|
432
478
|
# Errno::EBADF is infrequently raised
|
|
433
479
|
[@check, @notify].each do |io|
|
|
@@ -450,21 +496,25 @@ module Puma
|
|
|
450
496
|
client.env_set_http_version = @env_set_http_version
|
|
451
497
|
client.http_content_length_limit = @http_content_length_limit
|
|
452
498
|
client.supported_http_methods = @supported_http_methods
|
|
499
|
+
client.allow_underscore_headers = @allow_underscore_headers
|
|
500
|
+
client.continue_callback = @continue_callback
|
|
453
501
|
client
|
|
454
502
|
end
|
|
455
503
|
|
|
456
504
|
# :nodoc:
|
|
457
505
|
def handle_check
|
|
458
|
-
cmd = @check.
|
|
506
|
+
cmd = @check.sysread 1
|
|
459
507
|
|
|
460
508
|
case cmd
|
|
461
509
|
when STOP_COMMAND
|
|
510
|
+
shutdown_body_deadline
|
|
462
511
|
@status = :stop
|
|
463
512
|
return true
|
|
464
513
|
when HALT_COMMAND
|
|
465
514
|
@status = :halt
|
|
466
515
|
return true
|
|
467
516
|
when RESTART_COMMAND
|
|
517
|
+
shutdown_body_deadline
|
|
468
518
|
@status = :restart
|
|
469
519
|
return true
|
|
470
520
|
end
|
|
@@ -488,7 +538,9 @@ module Puma
|
|
|
488
538
|
requests = 0
|
|
489
539
|
|
|
490
540
|
begin
|
|
491
|
-
|
|
541
|
+
raise client.reactor_error if client.reactor_error
|
|
542
|
+
|
|
543
|
+
if @queue_requests && !client.eagerly_finish { shutdown_body_limit }
|
|
492
544
|
|
|
493
545
|
client.set_timeout(@first_data_timeout)
|
|
494
546
|
if @reactor.add client
|
|
@@ -498,7 +550,7 @@ module Puma
|
|
|
498
550
|
end
|
|
499
551
|
|
|
500
552
|
with_force_shutdown(client) do
|
|
501
|
-
client.finish(@first_data_timeout)
|
|
553
|
+
client.finish(@first_data_timeout) { shutdown_body_limit }
|
|
502
554
|
end
|
|
503
555
|
|
|
504
556
|
can_loop = true
|
|
@@ -519,7 +571,7 @@ module Puma
|
|
|
519
571
|
next_request_ready = if client.has_back_to_back_requests?
|
|
520
572
|
with_force_shutdown(client) { client.process_back_to_back_requests }
|
|
521
573
|
else
|
|
522
|
-
with_force_shutdown(client) { client.eagerly_finish }
|
|
574
|
+
with_force_shutdown(client) { client.eagerly_finish { shutdown_body_limit } }
|
|
523
575
|
end
|
|
524
576
|
|
|
525
577
|
if next_request_ready
|
|
@@ -528,8 +580,12 @@ module Puma
|
|
|
528
580
|
if @thread_pool.waiting > 0
|
|
529
581
|
can_loop = true
|
|
530
582
|
else
|
|
531
|
-
@thread_pool
|
|
532
|
-
|
|
583
|
+
@thread_pool.with_mutex do
|
|
584
|
+
unless shutting_down?
|
|
585
|
+
@thread_pool << client
|
|
586
|
+
close_socket = false
|
|
587
|
+
end
|
|
588
|
+
end
|
|
533
589
|
end
|
|
534
590
|
elsif @queue_requests
|
|
535
591
|
client.set_timeout @persistent_timeout
|
|
@@ -551,6 +607,25 @@ module Puma
|
|
|
551
607
|
end
|
|
552
608
|
end
|
|
553
609
|
|
|
610
|
+
# Accepting fails while the process is out of file descriptors or memory.
|
|
611
|
+
# The connection stays in the backlog, so retrying at once would spin and
|
|
612
|
+
# log at full speed. Wait briefly and log at most once per second.
|
|
613
|
+
def accept_resource_error(error)
|
|
614
|
+
now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
615
|
+
if @accept_error_logged_at.nil? || now - @accept_error_logged_at >= 1
|
|
616
|
+
suffix = @accept_errors_suppressed.to_i > 0 ? " (#{@accept_errors_suppressed} more suppressed)" : ""
|
|
617
|
+
@accept_error_logged_at = now
|
|
618
|
+
@accept_errors_suppressed = 0
|
|
619
|
+
begin
|
|
620
|
+
@log_writer.unknown_error error, nil, "Listen loop#{suffix}"
|
|
621
|
+
rescue StandardError
|
|
622
|
+
end
|
|
623
|
+
else
|
|
624
|
+
@accept_errors_suppressed += 1
|
|
625
|
+
end
|
|
626
|
+
sleep ACCEPT_ERROR_DELAY
|
|
627
|
+
end
|
|
628
|
+
|
|
554
629
|
# :nodoc:
|
|
555
630
|
def close_client_safely(client)
|
|
556
631
|
client.close
|
|
@@ -587,6 +662,13 @@ module Puma
|
|
|
587
662
|
when HttpParserError501
|
|
588
663
|
response_to_error(client, requests, e, 501)
|
|
589
664
|
@log_writer.parse_error e, client
|
|
665
|
+
when ContinueRejected
|
|
666
|
+
status, headers, res_body = e.response
|
|
667
|
+
begin
|
|
668
|
+
prepare_response(status, headers, res_body, requests, client)
|
|
669
|
+
ensure
|
|
670
|
+
res_body.close if res_body.respond_to? :close
|
|
671
|
+
end
|
|
590
672
|
else
|
|
591
673
|
response_to_error(client, requests, e, 500)
|
|
592
674
|
@log_writer.unknown_error e, nil, "Read"
|
|
@@ -628,9 +710,19 @@ module Puma
|
|
|
628
710
|
end
|
|
629
711
|
private :response_to_error
|
|
630
712
|
|
|
713
|
+
def shutdown_body_deadline
|
|
714
|
+
@shutdown_body_deadline ||= Process.clock_gettime(Process::CLOCK_MONOTONIC) + @shutdown_body_timeout
|
|
715
|
+
end
|
|
716
|
+
|
|
717
|
+
def shutdown_body_limit
|
|
718
|
+
@shutdown_body_deadline
|
|
719
|
+
end
|
|
720
|
+
|
|
631
721
|
# Wait for all outstanding requests to finish.
|
|
632
722
|
#
|
|
633
723
|
def graceful_shutdown
|
|
724
|
+
shutdown_body_deadline
|
|
725
|
+
|
|
634
726
|
if @status != :restart
|
|
635
727
|
@binder.close
|
|
636
728
|
end
|
|
@@ -639,16 +731,18 @@ module Puma
|
|
|
639
731
|
end
|
|
640
732
|
|
|
641
733
|
def notify_safely(message)
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
#
|
|
645
|
-
|
|
646
|
-
#
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
734
|
+
# Use write_nonblock rather than `<<` or `syswrite`. This method is
|
|
735
|
+
# called from signal handlers (TERM/USR2/INT/HUP, and the cluster
|
|
736
|
+
# worker's SIGTERM trap). On Ruby < 4.0, a blocking write from trap
|
|
737
|
+
# context that is still in flight when handle_servers' ensure block
|
|
738
|
+
# runs IO#close leaves the closing thread parked in IO#close forever
|
|
739
|
+
# (puma#3677). write_nonblock is a single write(2) that never waits,
|
|
740
|
+
# so IO#close has nothing to wait for. If the pipe is full a command
|
|
741
|
+
# is already pending, so dropping this one is harmless.
|
|
742
|
+
notify = @notify
|
|
743
|
+
notify.write_nonblock(message, exception: false) if notify && !notify.closed?
|
|
744
|
+
rescue IOError, NoMethodError, Errno::EPIPE, Errno::EBADF => e
|
|
745
|
+
@log_writer.unknown_error(e, nil, "notify_safely error") if Puma::IS_MRI && RUBY_VERSION > '3.3'
|
|
652
746
|
end
|
|
653
747
|
private :notify_safely
|
|
654
748
|
|
|
@@ -656,6 +750,7 @@ module Puma
|
|
|
656
750
|
# off the request queue before finally exiting.
|
|
657
751
|
|
|
658
752
|
def stop(sync=false)
|
|
753
|
+
shutdown_body_deadline
|
|
659
754
|
notify_safely(STOP_COMMAND)
|
|
660
755
|
@thread.join if @thread && sync
|
|
661
756
|
end
|
|
@@ -666,6 +761,7 @@ module Puma
|
|
|
666
761
|
end
|
|
667
762
|
|
|
668
763
|
def begin_restart(sync=false)
|
|
764
|
+
shutdown_body_deadline
|
|
669
765
|
notify_safely(RESTART_COMMAND)
|
|
670
766
|
@thread.join if @thread && sync
|
|
671
767
|
end
|
data/lib/puma/thread_pool.rb
CHANGED
|
@@ -7,7 +7,6 @@ require_relative 'server_plugin_control'
|
|
|
7
7
|
|
|
8
8
|
module Puma
|
|
9
9
|
|
|
10
|
-
# Add `Thread#puma_server` and `Thread#puma_server=`
|
|
11
10
|
Thread.attr_accessor(:puma_server)
|
|
12
11
|
|
|
13
12
|
# Internal Docs for A simple thread pool management object.
|
|
@@ -211,6 +210,7 @@ module Puma
|
|
|
211
210
|
processor.marked_as_io_thread = false
|
|
212
211
|
else
|
|
213
212
|
# We're already at max threads, so we exit the extra io thread.
|
|
213
|
+
@spawned -= 1
|
|
214
214
|
@processors.delete(processor)
|
|
215
215
|
trigger_before_thread_exit_hooks
|
|
216
216
|
Thread.exit
|
|
@@ -314,6 +314,17 @@ module Puma
|
|
|
314
314
|
end
|
|
315
315
|
end
|
|
316
316
|
|
|
317
|
+
def wait_until_not_full
|
|
318
|
+
with_mutex do
|
|
319
|
+
while true
|
|
320
|
+
return if @shutdown
|
|
321
|
+
return if (@spawned - @waiting + @todo.size) < @max
|
|
322
|
+
|
|
323
|
+
@not_full.wait @mutex
|
|
324
|
+
end
|
|
325
|
+
end
|
|
326
|
+
end
|
|
327
|
+
|
|
317
328
|
# @version 5.0.0
|
|
318
329
|
def with_mutex(&block)
|
|
319
330
|
@mutex.owned? ?
|
data/lib/puma/util.rb
CHANGED
|
@@ -13,21 +13,25 @@ module Puma
|
|
|
13
13
|
# Escapes and unescapes a URI escaped string with
|
|
14
14
|
# +encoding+. +encoding+ will be the target encoding of the string
|
|
15
15
|
# returned, and it defaults to UTF-8
|
|
16
|
+
#
|
|
17
|
+
# Unlike form encoding, escape writes a space as '%20' and unescape
|
|
18
|
+
# keeps a literal '+', so values such as OpenSSL cipher strings
|
|
19
|
+
# ("AES+SHA") survive.
|
|
16
20
|
if defined?(::Encoding)
|
|
17
21
|
def escape(s, encoding = Encoding::UTF_8)
|
|
18
|
-
URI.encode_www_form_component(s, encoding)
|
|
22
|
+
URI.encode_www_form_component(s, encoding).gsub('+', '%20')
|
|
19
23
|
end
|
|
20
24
|
|
|
21
25
|
def unescape(s, encoding = Encoding::UTF_8)
|
|
22
|
-
URI.decode_www_form_component(s, encoding)
|
|
26
|
+
URI.decode_www_form_component(s.gsub('+', '%2B'), encoding)
|
|
23
27
|
end
|
|
24
28
|
else
|
|
25
29
|
def escape(s, encoding = nil)
|
|
26
|
-
URI.encode_www_form_component(s, encoding)
|
|
30
|
+
URI.encode_www_form_component(s, encoding).gsub('+', '%20')
|
|
27
31
|
end
|
|
28
32
|
|
|
29
33
|
def unescape(s, encoding = nil)
|
|
30
|
-
URI.decode_www_form_component(s, encoding)
|
|
34
|
+
URI.decode_www_form_component(s.gsub('+', '%2B'), encoding)
|
|
31
35
|
end
|
|
32
36
|
end
|
|
33
37
|
module_function :unescape, :escape
|
data/lib/puma.rb
CHANGED
|
@@ -82,7 +82,7 @@ module Puma
|
|
|
82
82
|
#
|
|
83
83
|
def self.deprecate_method_change(method_old, method_caller, method_new)
|
|
84
84
|
if method_old == method_caller
|
|
85
|
-
warn "Use '#{method_new}', '#{method_caller}' is deprecated and will be removed in
|
|
85
|
+
warn "Use '#{method_new}', '#{method_caller}' is deprecated and will be removed in Puma v9"
|
|
86
86
|
end
|
|
87
87
|
end
|
|
88
88
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: puma
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 8.
|
|
4
|
+
version: 8.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Evan Phoenix
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 2026-11-16 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: nio4r
|
|
@@ -43,15 +43,19 @@ files:
|
|
|
43
43
|
- bin/puma
|
|
44
44
|
- bin/puma-wild
|
|
45
45
|
- bin/pumactl
|
|
46
|
-
- docs/5.0-Upgrade.md
|
|
47
|
-
- docs/6.0-Upgrade.md
|
|
48
|
-
- docs/7.0-Upgrade.md
|
|
49
|
-
- docs/8.0-Upgrade.md
|
|
50
46
|
- docs/architecture.md
|
|
47
|
+
- docs/binding.md
|
|
48
|
+
- docs/cluster_mode.md
|
|
51
49
|
- docs/compile_options.md
|
|
52
|
-
- docs/
|
|
53
|
-
- docs/
|
|
54
|
-
- docs/
|
|
50
|
+
- docs/configuration.md
|
|
51
|
+
- docs/control_server.md
|
|
52
|
+
- docs/deployment/README.md
|
|
53
|
+
- docs/deployment/kubernetes.md
|
|
54
|
+
- docs/deployment/nginx.md
|
|
55
|
+
- docs/deployment/rc.d/README.md
|
|
56
|
+
- docs/deployment/rc.d/puma
|
|
57
|
+
- docs/deployment/rc.d/puma.conf
|
|
58
|
+
- docs/deployment/systemd.md
|
|
55
59
|
- docs/images/favicon.svg
|
|
56
60
|
- docs/images/puma-connection-flow-no-reactor.png
|
|
57
61
|
- docs/images/puma-connection-flow.png
|
|
@@ -59,33 +63,19 @@ files:
|
|
|
59
63
|
- docs/images/running-puma.svg
|
|
60
64
|
- docs/images/standard-logo.svg
|
|
61
65
|
- docs/java_options.md
|
|
62
|
-
- docs/jungle/README.md
|
|
63
|
-
- docs/jungle/rc.d/README.md
|
|
64
|
-
- docs/jungle/rc.d/puma
|
|
65
|
-
- docs/jungle/rc.d/puma.conf
|
|
66
|
-
- docs/kubernetes.md
|
|
67
|
-
- docs/nginx.md
|
|
68
66
|
- docs/plugins.md
|
|
67
|
+
- docs/puma_support.md
|
|
69
68
|
- docs/rails_dev_mode.md
|
|
70
69
|
- docs/restart.md
|
|
71
70
|
- docs/signals.md
|
|
72
|
-
- docs/
|
|
73
|
-
- docs/
|
|
74
|
-
- docs/
|
|
75
|
-
- docs/
|
|
76
|
-
- ext/puma_http11/PumaHttp11Service.java
|
|
71
|
+
- docs/upgrading/5.0-Upgrade.md
|
|
72
|
+
- docs/upgrading/6.0-Upgrade.md
|
|
73
|
+
- docs/upgrading/7.0-Upgrade.md
|
|
74
|
+
- docs/upgrading/8.0-Upgrade.md
|
|
77
75
|
- ext/puma_http11/extconf.rb
|
|
78
76
|
- ext/puma_http11/http11_parser.c
|
|
79
77
|
- ext/puma_http11/http11_parser.h
|
|
80
|
-
- ext/puma_http11/http11_parser.java.rl
|
|
81
|
-
- ext/puma_http11/http11_parser.rl
|
|
82
|
-
- ext/puma_http11/http11_parser_common.rl
|
|
83
78
|
- ext/puma_http11/mini_ssl.c
|
|
84
|
-
- ext/puma_http11/no_ssl/PumaHttp11Service.java
|
|
85
|
-
- ext/puma_http11/org/jruby/puma/EnvKey.java
|
|
86
|
-
- ext/puma_http11/org/jruby/puma/Http11.java
|
|
87
|
-
- ext/puma_http11/org/jruby/puma/Http11Parser.java
|
|
88
|
-
- ext/puma_http11/org/jruby/puma/MiniSSL.java
|
|
89
79
|
- ext/puma_http11/puma_http11.c
|
|
90
80
|
- lib/puma.rb
|
|
91
81
|
- lib/puma/app/status.rb
|
|
@@ -131,8 +121,6 @@ files:
|
|
|
131
121
|
- lib/puma/thread_pool.rb
|
|
132
122
|
- lib/puma/util.rb
|
|
133
123
|
- lib/rack/handler/puma.rb
|
|
134
|
-
- tools/Dockerfile
|
|
135
|
-
- tools/trickletest.rb
|
|
136
124
|
homepage: https://puma.io
|
|
137
125
|
licenses:
|
|
138
126
|
- BSD-3-Clause
|
|
@@ -157,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
157
145
|
- !ruby/object:Gem::Version
|
|
158
146
|
version: '0'
|
|
159
147
|
requirements: []
|
|
160
|
-
rubygems_version: 4.0.
|
|
148
|
+
rubygems_version: 4.0.20
|
|
161
149
|
specification_version: 4
|
|
162
150
|
summary: A Ruby/Rack web server built for parallelism.
|
|
163
151
|
test_files: []
|
data/docs/fork_worker.md
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
# Fork-Worker Cluster Mode [Experimental]
|
|
2
|
-
|
|
3
|
-
Puma 5 introduces an experimental new cluster-mode configuration option, `fork_worker` (`--fork-worker` from the CLI). This mode causes Puma to fork additional workers from worker 0, instead of directly from the master process:
|
|
4
|
-
|
|
5
|
-
```
|
|
6
|
-
10000 \_ puma 4.3.3 (tcp://0.0.0.0:9292) [puma]
|
|
7
|
-
10001 \_ puma: cluster worker 0: 10000 [puma]
|
|
8
|
-
10002 \_ puma: cluster worker 1: 10000 [puma]
|
|
9
|
-
10003 \_ puma: cluster worker 2: 10000 [puma]
|
|
10
|
-
10004 \_ puma: cluster worker 3: 10000 [puma]
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
The `fork_worker` option allows your application to be initialized only once for copy-on-write memory savings, and it has two additional advantages:
|
|
14
|
-
|
|
15
|
-
1. **Compatible with phased restart.** Because the master process itself doesn't preload the application, this mode works with phased restart (`SIGUSR1` or `pumactl phased-restart`). When worker 0 reloads as part of a phased restart, it initializes a new copy of your application first, then the other workers reload by forking from this new worker already containing the new preloaded application.
|
|
16
|
-
|
|
17
|
-
This allows a phased restart to complete as quickly as a hot restart (`SIGUSR2` or `pumactl restart`), while still minimizing downtime by staggering the restart across cluster workers.
|
|
18
|
-
|
|
19
|
-
2. **'Refork' for additional copy-on-write improvements in running applications.** Fork-worker mode introduces a new `refork` command that re-loads all nonzero workers by re-forking them from worker 0.
|
|
20
|
-
|
|
21
|
-
This command can potentially improve memory utilization in large or complex applications that don't fully pre-initialize on startup, because the re-forked workers can share copy-on-write memory with a worker that has been running for a while and serving requests.
|
|
22
|
-
|
|
23
|
-
You can trigger a refork by sending the cluster the `SIGURG` signal or running the `pumactl refork` command at any time. A refork will also automatically trigger once, after a certain number of requests have been processed by worker 0 (default 1000). To configure the number of requests before the auto-refork, pass a positive integer argument to `fork_worker` (e.g., `fork_worker 1000`), or `0` to disable.
|
|
24
|
-
|
|
25
|
-
### Usage Considerations
|
|
26
|
-
|
|
27
|
-
- `fork_worker` introduces new `before_refork` and `after_refork` configuration hooks. Note the following:
|
|
28
|
-
- When initially forking the parent process to the worker 0 child, `before_fork` will trigger on the parent process and `before_worker_boot` will trigger on the worker 0 child as normal.
|
|
29
|
-
- When forking the worker 0 child to grandchild workers, `before_refork` and `after_refork` will trigger on the worker 0 child, and `before_worker_boot` will trigger on each grandchild worker.
|
|
30
|
-
- For clarity, `before_fork` does not trigger on worker 0, and `after_refork` does not trigger on the grandchild.
|
|
31
|
-
- As a general migration guide:
|
|
32
|
-
- Copy any logic within your existing `before_fork` hook to the `before_refork` hook.
|
|
33
|
-
- Consider to copy logic from your `before_worker_boot` hook to the `after_refork` hook, if it is needed to reset the state of worker 0 after it forks.
|
|
34
|
-
|
|
35
|
-
### Limitations
|
|
36
|
-
|
|
37
|
-
- This mode is still very experimental so there may be bugs or edge-cases, particularly around expected behavior of existing hooks. Please open a [bug report](https://github.com/puma/puma/issues/new?template=bug_report.md) if you encounter any issues.
|
|
38
|
-
|
|
39
|
-
- In order to fork new workers cleanly, worker 0 shuts down its server and stops serving requests so there are no open file descriptors or other kinds of shared global state between processes, and to maximize copy-on-write efficiency across the newly-forked workers. This may temporarily reduce total capacity of the cluster during a phased restart / refork.
|
|
40
|
-
|
|
41
|
-
- In a cluster with `n` workers, a normal phased restart stops and restarts workers one by one while the application is loaded in each process, so `n-1` workers are available serving requests during the restart. In a phased restart in fork-worker mode, the application is first loaded in worker 0 while `n-1` workers are available, then worker 0 remains stopped while the rest of the workers are reloaded one by one, leaving only `n-2` workers to be available for a brief period of time. Reloading the rest of the workers should be quick because the application is preloaded at that point, but there may be situations where it can take longer (slow clients, long-running application code, slow worker-fork hooks, etc).
|
data/docs/grpc.md
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
# Using gRPC with Puma in Clustered Mode
|
|
2
|
-
|
|
3
|
-
This guide shows how to set up gRPC with Puma in a clustered environment using Puma's hooks to manage gRPC's lifecycle methods during forking.
|
|
4
|
-
|
|
5
|
-
## The Problem
|
|
6
|
-
|
|
7
|
-
In a clustered Puma setup, you might encounter the following error when using gRPC:
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
grpc cannot be used between calls to GRPC.prefork and GRPC.postfork_child or GRPC.postfork_parent
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
To work correctly, gRPC needs these methods called at specific points in the process lifecycle:
|
|
14
|
-
- `GRPC.prefork`: Called before forking.
|
|
15
|
-
- `GRPC.postfork_child`: Called in the child process after forking.
|
|
16
|
-
- `GRPC.postfork_parent`: Called in the parent process after forking.
|
|
17
|
-
|
|
18
|
-
Puma provides hooks such as `before_worker_fork`, `after_worker_fork`, and `before_worker_boot` to execute code during these lifecycle events. Understanding the behavior of these hooks is key to ensuring gRPC operates correctly in a clustered setup.
|
|
19
|
-
|
|
20
|
-
## The Solution
|
|
21
|
-
|
|
22
|
-
### Example Configuration
|
|
23
|
-
|
|
24
|
-
This configuration integrates gRPC's lifecycle methods in a clustered Puma setup and works whether preloading is enabled or not.
|
|
25
|
-
|
|
26
|
-
```ruby
|
|
27
|
-
# config/puma.rb
|
|
28
|
-
|
|
29
|
-
is_mac = RUBY_PLATFORM.include?("darwin")
|
|
30
|
-
|
|
31
|
-
before_worker_fork do |index|
|
|
32
|
-
GRPC.prefork unless is_mac
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
after_worker_fork do |index|
|
|
36
|
-
GRPC.postfork_parent unless is_mac
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
before_worker_boot do
|
|
40
|
-
GRPC.postfork_child unless is_mac
|
|
41
|
-
end
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
### Understanding the Lifecycle and Hooks
|
|
45
|
-
|
|
46
|
-
Puma's hooks determine when to call gRPC's lifecycle methods. Each hook plays a specific role in managing the lifecycle during forking:
|
|
47
|
-
|
|
48
|
-
- **`before_worker_fork`**:
|
|
49
|
-
- This hook runs before forking workers and is where you call `GRPC.prefork`.
|
|
50
|
-
- In preloading setups (default in Puma v7), it runs in the **master process** before workers are forked, as the application is preloaded in the master process.
|
|
51
|
-
- Without preloading, it still runs in the **master process** before forking workers, but the application is not preloaded.
|
|
52
|
-
- `GRPC.prefork` is called here to prepare GRPC for the forking process.
|
|
53
|
-
|
|
54
|
-
- **`after_worker_fork`**:
|
|
55
|
-
- This hook always runs in the **master process** after a worker is forked, regardless of whether preloading is enabled.
|
|
56
|
-
- Call `GRPC.postfork_parent` here to finalize the master process's state after forking.
|
|
57
|
-
|
|
58
|
-
- **`before_worker_boot`**:
|
|
59
|
-
- This hook always runs in the **worker process** after it is forked, regardless of whether preloading is enabled.
|
|
60
|
-
- Call `GRPC.postfork_child` here to finalize the worker's state.
|
|
61
|
-
|
|
62
|
-
**Note**: On macOS, these methods are skipped because gRPC does not require them due to differences in how forking works.
|