puma 8.0.3-java → 8.1.0-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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +115 -0
  3. data/README.md +20 -5
  4. data/docs/6.0-Upgrade.md +1 -1
  5. data/docs/8.0-Upgrade.md +2 -2
  6. data/docs/deployment.md +3 -3
  7. data/docs/fork_worker.md +34 -4
  8. data/docs/kubernetes.md +3 -3
  9. data/docs/plugins.md +2 -2
  10. data/docs/puma_support.md +78 -0
  11. data/docs/rails_dev_mode.md +2 -2
  12. data/docs/restart.md +4 -3
  13. data/docs/signals.md +2 -2
  14. data/docs/stats.md +5 -5
  15. data/docs/systemd.md +4 -2
  16. data/docs/testing_benchmarks_local_files.md +1 -1
  17. data/docs/testing_test_rackup_ci_files.md +2 -2
  18. data/ext/puma_http11/extconf.rb +2 -0
  19. data/ext/puma_http11/http11_parser.c +6 -2
  20. data/ext/puma_http11/http11_parser_common.rl +4 -1
  21. data/ext/puma_http11/mini_ssl.c +8 -4
  22. data/ext/puma_http11/org/jruby/puma/Http11Parser.java +36 -36
  23. data/ext/puma_http11/puma_http11.c +24 -0
  24. data/lib/puma/binder.rb +29 -0
  25. data/lib/puma/cli.rb +6 -0
  26. data/lib/puma/client.rb +75 -29
  27. data/lib/puma/client_env.rb +32 -18
  28. data/lib/puma/cluster/worker.rb +109 -33
  29. data/lib/puma/cluster/worker_handle.rb +16 -0
  30. data/lib/puma/cluster.rb +173 -44
  31. data/lib/puma/commonlogger.rb +3 -3
  32. data/lib/puma/configuration.rb +22 -3
  33. data/lib/puma/const.rb +11 -9
  34. data/lib/puma/dsl.rb +265 -91
  35. data/lib/puma/launcher.rb +6 -4
  36. data/lib/puma/minissl.rb +1 -1
  37. data/lib/puma/plugin/systemd.rb +1 -1
  38. data/lib/puma/puma_http11.jar +0 -0
  39. data/lib/puma/response.rb +13 -5
  40. data/lib/puma/runner.rb +5 -1
  41. data/lib/puma/sd_notify.rb +4 -1
  42. data/lib/puma/server.rb +45 -20
  43. data/lib/puma/thread_pool.rb +12 -1
  44. data/lib/puma.rb +1 -1
  45. metadata +3 -2
data/lib/puma/dsl.rb CHANGED
@@ -5,7 +5,7 @@ require_relative 'util'
5
5
 
6
6
  module Puma
7
7
  # The methods that are available for use inside the configuration file.
8
- # These same methods are used in Puma cli and the rack handler
8
+ # These same methods are used in Puma CLI and the Rack handler
9
9
  # internally.
10
10
  #
11
11
  # Used manually (via CLI class):
@@ -33,12 +33,12 @@ module Puma
33
33
  # +test/config+.
34
34
  #
35
35
  # Puma v6 adds the option to specify a key name (String or Symbol) to the
36
- # hooks that run inside the forked workers. All the hooks run inside the
36
+ # hooks that run inside the forked workers. All the hooks run inside the
37
37
  # {Puma::Cluster::Worker#run} method.
38
38
  #
39
39
  # Previously, the worker index and the LogWriter instance were passed to the
40
- # hook blocks/procs. If a key name is specified, a hash is passed as the last
41
- # parameter. This allows storage of data, typically objects that are created
40
+ # hook blocks/procs. If a key name is specified, a hash is passed as the last
41
+ # parameter. This allows storage of data, typically objects that are created
42
42
  # before the worker that need to be passed to the hook when the worker is shutdown.
43
43
  #
44
44
  # The following hooks have been updated:
@@ -48,6 +48,8 @@ module Puma
48
48
  # | before_worker_shutdown | :before_worker_shutdown | inside, after |
49
49
  # | before_refork | :before_refork | inside |
50
50
  # | after_refork | :after_refork | inside |
51
+ # | after_mold_promotion | :after_mold_promotion | inside |
52
+ # | before_mold_shutdown | :before_mold_shutdown | inside |
51
53
  #
52
54
  class DSL
53
55
  ON_WORKER_KEY = [String, Symbol].freeze
@@ -299,19 +301,16 @@ module Puma
299
301
  # Bind to (systemd) activated sockets, regardless of configured binds.
300
302
  #
301
303
  # Systemd can present sockets as file descriptors that are already opened.
302
- # By default Puma will use these but only if it was explicitly told to bind
303
- # to the socket. If not, it will close the activated sockets. This means
304
- # all configuration is duplicated.
304
+ # By default Puma only uses these if it was explicitly told to bind to
305
+ # the socket, otherwise it closes them. Since only SSL config on a bind
306
+ # is relevant for activated sockets (unix and TCP socket options are
307
+ # ignored), this often means duplicating configuration for no benefit.
305
308
  #
306
- # Binds can contain additional configuration, but only SSL config is really
307
- # relevant since the unix and TCP socket options are ignored.
309
+ # This method tells the launcher to bind to all activated sockets,
310
+ # regardless of existing binds. Passing `'only'` also clears any
311
+ # configured binds so that only activated sockets are used.
308
312
  #
309
- # This means there is a lot of duplicated configuration for no additional
310
- # value in most setups. This method tells the launcher to bind to all
311
- # activated sockets, regardless of existing bind.
312
- #
313
- # To clear configured binds, the value only can be passed. This will clear
314
- # out any binds that may have been configured.
313
+ # The default is +nil+.
315
314
  #
316
315
  # @example Use any systemd activated sockets as well as configured binds
317
316
  # bind_to_activated_sockets
@@ -335,7 +334,7 @@ module Puma
335
334
  bind URI::Generic.build(scheme: 'tcp', host: host, port: Integer(port)).to_s
336
335
  end
337
336
 
338
- # Define how long the tcp socket stays open, if no data has been received.
337
+ # Define how long the TCP socket stays open when no data has been received.
339
338
  #
340
339
  # The default is 30 seconds.
341
340
  #
@@ -390,8 +389,12 @@ module Puma
390
389
  alias clean_thread_locals fiber_per_request
391
390
 
392
391
  # When shutting down, drain the accept socket of pending connections and
393
- # process them. This loops over the accept socket until there are no more
394
- # read events and then stops looking and waits for the requests to finish.
392
+ # process them before waiting for in-flight requests to finish.
393
+ #
394
+ # The default is +nil+.
395
+ #
396
+ # @example
397
+ # drain_on_shutdown
395
398
  #
396
399
  # @see Puma::Server#graceful_shutdown
397
400
  #
@@ -425,14 +428,17 @@ module Puma
425
428
  end
426
429
 
427
430
  # How long to wait for threads to stop when shutting them down.
428
- # Specifying :immediately will cause Puma to kill the threads immediately.
431
+ # Specifying `:immediately` will cause Puma to kill the threads immediately.
429
432
  # Otherwise the value is the number of seconds to wait.
430
433
  #
431
434
  # Puma always waits a few seconds after killing a thread for it to try
432
- # to finish up it's work, even in :immediately mode.
435
+ # to finish up its work, even in `:immediately` mode.
433
436
  #
434
437
  # The default is +:forever+.
435
438
  #
439
+ # @example
440
+ # force_shutdown_after 30
441
+ #
436
442
  # @see Puma::Server#graceful_shutdown
437
443
  #
438
444
  def force_shutdown_after(val=:forever)
@@ -467,7 +473,7 @@ module Puma
467
473
  alias_method :on_restart, :before_restart
468
474
 
469
475
  # Command to use to restart Puma. This should be just how to
470
- # load Puma itself (ie. 'ruby -Ilib bin/puma'), not the arguments
476
+ # load Puma itself (i.e. `ruby -Ilib bin/puma`), not the arguments
471
477
  # to Puma, as those are the same as the original process.
472
478
  #
473
479
  # @example
@@ -477,7 +483,7 @@ module Puma
477
483
  @options[:restart_cmd] = cmd.to_s
478
484
  end
479
485
 
480
- # Store the pid of the server in the file at "path".
486
+ # Store the PID of the server in the file at +path+.
481
487
  #
482
488
  # @example
483
489
  # pidfile '/u/apps/lolcat/tmp/pids/puma.pid'
@@ -488,11 +494,13 @@ module Puma
488
494
 
489
495
  # Disable request logging, the inverse of `log_requests`.
490
496
  #
491
- # The default is +true+.
497
+ # The default is +false+.
492
498
  #
493
499
  # @example
494
500
  # quiet
495
501
  #
502
+ # @see log_requests
503
+ #
496
504
  def quiet(which=true)
497
505
  @options[:log_requests] = !which
498
506
  end
@@ -504,11 +512,13 @@ module Puma
504
512
  # @example
505
513
  # log_requests
506
514
  #
515
+ # @see quiet
516
+ #
507
517
  def log_requests(which=true)
508
518
  @options[:log_requests] = which
509
519
  end
510
520
 
511
- # Pass in a custom logging class instance
521
+ # Pass in a custom logging class instance.
512
522
  #
513
523
  # @example
514
524
  # custom_logger Logger.new('t.log')
@@ -517,7 +527,7 @@ module Puma
517
527
  @options[:custom_logger] = custom_logger
518
528
  end
519
529
 
520
- # Show debugging info
530
+ # Show debugging info.
521
531
  #
522
532
  # The default is +false+.
523
533
  #
@@ -539,9 +549,14 @@ module Puma
539
549
  @options[:rackup] ||= path.to_s
540
550
  end
541
551
 
542
- # Allows setting `env['rack.url_scheme']`.
543
- # Only necessary if X-Forwarded-Proto is not being set by your proxy
544
- # Normal values are 'http' or 'https'.
552
+ # Set `env['rack.url_scheme']`. Only necessary if `X-Forwarded-Proto`
553
+ # is not being set by your proxy. Normal values are `'http'` or
554
+ # `'https'`.
555
+ #
556
+ # The default is +nil+.
557
+ #
558
+ # @example
559
+ # rack_url_scheme 'https'
545
560
  #
546
561
  def rack_url_scheme(scheme=nil)
547
562
  @options[:rack_url_scheme] = scheme
@@ -559,9 +574,7 @@ module Puma
559
574
  end
560
575
 
561
576
  # Redirect +STDOUT+ and +STDERR+ to files specified. The +append+ parameter
562
- # specifies whether the output is appended.
563
- #
564
- # The default is +false+.
577
+ # specifies whether the output is appended, and defaults to +false+.
565
578
  #
566
579
  # @example
567
580
  # stdout_redirect '/app/lolcat/log/stdout', '/app/lolcat/log/stderr'
@@ -574,6 +587,16 @@ module Puma
574
587
  @options[:redirect_append] = append
575
588
  end
576
589
 
590
+ # Provide a block to format log messages. The block receives the message
591
+ # string and should return the formatted string.
592
+ #
593
+ # @example
594
+ # log_formatter do |str|
595
+ # "[#{Time.now}] #{str}"
596
+ # end
597
+ #
598
+ # @see Puma::LogWriter
599
+ #
577
600
  def log_formatter(&block)
578
601
  @options[:log_formatter] = block
579
602
  end
@@ -582,10 +605,10 @@ module Puma
582
605
  #
583
606
  # It can be a single fixed number, or a +min+ and a +max+.
584
607
  #
585
- # The default is the environment variables +PUMA_MIN_THREADS+ / +PUMA_MAX_THREADS+
586
- # (or +MIN_THREADS+ / +MAX_THREADS+ if the +PUMA_+ variables aren't set).
587
- #
588
- # If these environment variables aren't set, the default is "0, 5" in MRI or "0, 16" for other interpreters.
608
+ # The default is taken from the +PUMA_MIN_THREADS+ / +PUMA_MAX_THREADS+
609
+ # environment variables (or +MIN_THREADS+ / +MAX_THREADS+ if the +PUMA_+
610
+ # variables are not set). If those environment variables are also unset,
611
+ # the default is `0, 5` in MRI or `0, 16` for other interpreters.
589
612
  #
590
613
  # @example
591
614
  # threads 5
@@ -614,15 +637,17 @@ module Puma
614
637
  # When request handlers know the current requests will no longer use a significant amount
615
638
  # of CPU, they can mark the current request as IO bound using <tt>env["puma.mark_as_io_bound"]</tt>.
616
639
  #
617
- # Threads marked as IO bound are allowed to go over the max thread limit.
640
+ # Threads marked as IO bound are allowed to go over the max thread limit. Any IO thread
641
+ # over the limit is counted as a regular thread, so a configuration of 5 regular threads
642
+ # and 5 IO threads may also allow, for example, 3 regular threads and 7 IO threads to
643
+ # process requests concurrently.
644
+ #
645
+ # The default is +0+.
618
646
  #
619
647
  # @example
620
648
  # threads 5
621
649
  # max_io_threads 5
622
650
  #
623
- # The above example allows for 5 regular threads and 5 IO threads to process requests concurrently.
624
- # Any IO thread over the limit is counted as a regular thread, hence the above configuration also
625
- # allows for 3 regular threads and 7 IO threads for example.
626
651
  def max_io_threads(max)
627
652
  max = Integer(max)
628
653
  if max < 0
@@ -636,7 +661,7 @@ module Puma
636
661
  #
637
662
  # bind 'ssl://127.0.0.1:9292?key=key_path&cert=cert_path'
638
663
  #
639
- # you can use the this method.
664
+ # you can use this method.
640
665
  #
641
666
  # When binding on localhost you don't need to specify +cert+ and +key+,
642
667
  # Puma will assume you are using the +localhost+ gem and try to load the
@@ -649,8 +674,8 @@ module Puma
649
674
  # The `cert:` options hash parameter can be the path to a certificate
650
675
  # file including all intermediate certificates in PEM format.
651
676
  #
652
- # The `cert_pem:` options hash parameter can be String containing the
653
- # cerificate and all intermediate certificates in PEM format.
677
+ # The `cert_pem:` options hash parameter can be a String containing the
678
+ # certificate and all intermediate certificates in PEM format.
654
679
  #
655
680
  # @example
656
681
  # ssl_bind '127.0.0.1', '9292', {
@@ -696,7 +721,7 @@ module Puma
696
721
  @options[:state] = path.to_s
697
722
  end
698
723
 
699
- # Use +permission+ to restrict permissions for the state file. By convention,
724
+ # Use +permission+ to restrict permissions for the state file. By convention,
700
725
  # +permission+ is an octal number (e.g. `0640` or `0o640`).
701
726
  #
702
727
  # @example
@@ -747,13 +772,13 @@ module Puma
747
772
  # @note Cluster mode only.
748
773
  #
749
774
  # @example
750
- # silence_single_worker_warning
775
+ # silence_single_worker_warning
751
776
  #
752
777
  def silence_single_worker_warning
753
778
  @options[:silence_single_worker_warning] = true
754
779
  end
755
780
 
756
- # Disable warning message when running single mode with callback hook defined.
781
+ # Disable the warning when running in single mode with a cluster-only callback hook defined.
757
782
  #
758
783
  # The default is +false+.
759
784
  #
@@ -822,8 +847,8 @@ module Puma
822
847
  process_hook :before_fork, nil, block, cluster_only: true
823
848
  end
824
849
 
825
- # Code to run in a worker when it boots to setup
826
- # the process before booting the app.
850
+ # Code to run in a worker on boot to set up the process before
851
+ # the app is loaded. The worker's index is passed as an argument.
827
852
  #
828
853
  # This can be called multiple times to add several hooks.
829
854
  #
@@ -888,7 +913,7 @@ module Puma
888
913
  # Code to run in the master after a worker has been started. The worker's
889
914
  # index is passed as an argument.
890
915
  #
891
- # This is called everytime a worker is to be started.
916
+ # This is called every time a worker is to be started.
892
917
  #
893
918
  # @note Cluster mode only.
894
919
  #
@@ -903,8 +928,10 @@ module Puma
903
928
 
904
929
  alias_method :after_worker_boot, :after_worker_fork
905
930
 
906
- # Code to run in the master right after a worker has stopped. The worker's
907
- # index and Process::Status are passed as arguments.
931
+ # Code to run in the master right after a worker has stopped. A
932
+ # `Puma::Cluster::WorkerHandle` is passed as an argument.
933
+ #
934
+ # This can be called multiple times to add several hooks.
908
935
  #
909
936
  # @note Cluster mode only.
910
937
  #
@@ -917,7 +944,7 @@ module Puma
917
944
  process_hook :after_worker_shutdown, nil, block, cluster_only: true
918
945
  end
919
946
 
920
- # Code to run after puma is booted (works for both single and cluster modes).
947
+ # Code to run after Puma is booted (works for both single and cluster modes).
921
948
  #
922
949
  # @example
923
950
  # after_booted do
@@ -932,7 +959,7 @@ module Puma
932
959
 
933
960
  alias_method :on_booted, :after_booted
934
961
 
935
- # Code to run after puma is stopped (works for both: single and clustered)
962
+ # Code to run after Puma is stopped (works for both single and cluster modes).
936
963
  #
937
964
  # @example
938
965
  # after_stopped do
@@ -995,10 +1022,47 @@ module Puma
995
1022
  process_hook :after_refork, key, block
996
1023
  end
997
1024
 
1025
+ # When `mold_worker` is enabled, code to run in a worker after it stops
1026
+ # serving requests and becomes a mold, before any workers are forked from it.
1027
+ # The worker's index is passed as an argument.
1028
+ #
1029
+ # This can be used to close any connections to remote servers (database,
1030
+ # Redis, ...) or to run garbage collection to maximize copy-on-write
1031
+ # efficiency.
1032
+ #
1033
+ # This can be called multiple times to add several hooks.
1034
+ #
1035
+ # @note Cluster mode with `mold_worker` enabled only.
1036
+ #
1037
+ # @example
1038
+ # after_mold_promotion do
1039
+ # 3.times { GC.start }
1040
+ # end
1041
+ #
1042
+ def after_mold_promotion(key = nil, &block)
1043
+ process_hook :after_mold_promotion, key, block, cluster_only: true
1044
+ end
1045
+
1046
+ # When `mold_worker` is enabled, code to run in a mold before it exits.
1047
+ # The mold's index is passed as an argument.
1048
+ #
1049
+ # This can be called multiple times to add several hooks.
1050
+ #
1051
+ # @note Cluster mode with `mold_worker` enabled only.
1052
+ #
1053
+ # @example
1054
+ # before_mold_shutdown do
1055
+ # puts 'Mold shutting down...'
1056
+ # end
1057
+ #
1058
+ def before_mold_shutdown(key = nil, &block)
1059
+ process_hook :before_mold_shutdown, key, block, cluster_only: true
1060
+ end
1061
+
998
1062
  # Provide a block to be executed just before a thread is added to the thread
999
- # pool. Be careful: while the block executes, thread creation is delayed, and
1000
- # probably a request will have to wait too! The new thread will not be added to
1001
- # the threadpool until the provided block returns.
1063
+ # pool. Note that while the block executes, thread creation is delayed, and
1064
+ # a request may have to wait. The new thread will not be added to the
1065
+ # threadpool until the provided block returns.
1002
1066
  #
1003
1067
  # Return values are ignored.
1004
1068
  # Raising an exception will log a warning.
@@ -1021,8 +1085,8 @@ module Puma
1021
1085
  alias_method :on_thread_start, :before_thread_start
1022
1086
 
1023
1087
  # Provide a block to be executed after a thread is trimmed from the thread
1024
- # pool. Be careful: while this block executes, Puma's main loop is
1025
- # blocked, so no new requests will be picked up.
1088
+ # pool. Note that while this block executes, Puma's main loop is blocked,
1089
+ # so no new requests will be picked up.
1026
1090
  #
1027
1091
  # This hook only runs when a thread in the threadpool is trimmed by Puma.
1028
1092
  # It does not run when a thread dies due to exceptions or any other cause.
@@ -1058,6 +1122,11 @@ module Puma
1058
1122
  #
1059
1123
  # This can be called multiple times to add several hooks.
1060
1124
  #
1125
+ # @example
1126
+ # out_of_band do
1127
+ # GC.start
1128
+ # end
1129
+ #
1061
1130
  def out_of_band(&block)
1062
1131
  process_hook :out_of_band, nil, block
1063
1132
  end
@@ -1102,6 +1171,43 @@ module Puma
1102
1171
  @options[:lowlevel_error_handler] = obj
1103
1172
  end
1104
1173
 
1174
+ # Use +obj+ or +block+ to handle exceptions raised by +before_fork+,
1175
+ # +before_worker_fork+, +after_worker_fork+, +before_worker_boot+,
1176
+ # +before_worker_shutdown+, +after_worker_shutdown+, +before_refork+,
1177
+ # +after_refork+, +after_mold_promotion+, +before_mold_shutdown+, and
1178
+ # +before_restart+ hooks.
1179
+ #
1180
+ # @example Crash workers instead of booting them half-configured
1181
+ # master_pid = Process.pid
1182
+ # hook_error_handler do |err, hook|
1183
+ # raise err unless Process.pid == master_pid
1184
+ # end
1185
+ #
1186
+ def hook_error_handler(obj=nil, &block)
1187
+ obj ||= block
1188
+ raise "Provide either a #call'able or a block" unless obj
1189
+ @options[:hook_error_handler] = obj
1190
+ end
1191
+
1192
+ # Use +obj+ or +block+ to answer a request that sends
1193
+ # <tt>Expect: 100-continue</tt> before Puma replies +100 Continue+ and reads
1194
+ # the body. It receives the Rack env (headers, no body) and can run on the
1195
+ # reactor thread, so it must return quickly.
1196
+ #
1197
+ # Return +false+ to carry on as usual, or a Rack response to send instead:
1198
+ # the app is not called and the connection is closed afterwards.
1199
+ #
1200
+ # @example Refuse oversized uploads without receiving them
1201
+ # continue_callback do |env|
1202
+ # env['CONTENT_LENGTH'].to_i > 10_000_000 ? [413, {}, []] : false
1203
+ # end
1204
+ #
1205
+ def continue_callback(obj=nil, &block)
1206
+ obj ||= block
1207
+ raise "Provide either a #call'able or a block" unless obj
1208
+ @options[:continue_callback] = obj
1209
+ end
1210
+
1105
1211
  # This option is used to allow your app and its gems to be
1106
1212
  # properly reloaded when not using preload.
1107
1213
  #
@@ -1115,9 +1221,14 @@ module Puma
1115
1221
  # new Bundler context and thus can float around as the release
1116
1222
  # dictates.
1117
1223
  #
1224
+ # The default is +false+.
1225
+ #
1118
1226
  # @note Cluster mode only.
1119
1227
  # @note This is incompatible with +preload_app!+.
1120
- # @note This is only supported for RubyGems 2.2+
1228
+ # @note This is only supported for RubyGems 2.2+.
1229
+ #
1230
+ # @example
1231
+ # prune_bundler
1121
1232
  #
1122
1233
  # @see extra_runtime_dependencies
1123
1234
  #
@@ -1177,7 +1288,7 @@ module Puma
1177
1288
  @options[:tag] = string.to_s
1178
1289
  end
1179
1290
 
1180
- # Change the default interval for checking workers.
1291
+ # Set the interval for checking workers.
1181
1292
  #
1182
1293
  # The default is 5 seconds.
1183
1294
  #
@@ -1189,13 +1300,13 @@ module Puma
1189
1300
  # @see Puma::Cluster#check_workers
1190
1301
  #
1191
1302
  def worker_check_interval(interval)
1192
- @options[:worker_check_interval] = Integer(interval)
1303
+ @options[:worker_check_interval] = Float(interval)
1193
1304
  end
1194
1305
 
1195
1306
  # Verifies that all workers have checked in to the master process within
1196
- # the given timeout. If not the worker process will be restarted. This is
1197
- # not a request timeout, it is to protect against a hung or dead process.
1198
- # Setting this value will not protect against slow requests.
1307
+ # the given timeout. If not, the worker process will be restarted. This
1308
+ # is not a request timeout, it is to protect against a hung or dead
1309
+ # process. Setting this value will not protect against slow requests.
1199
1310
  #
1200
1311
  # This value must be greater than worker_check_interval.
1201
1312
  #
@@ -1219,7 +1330,7 @@ module Puma
1219
1330
  @options[:worker_timeout] = timeout
1220
1331
  end
1221
1332
 
1222
- # Change the default worker timeout for booting.
1333
+ # Set the worker timeout for booting.
1223
1334
  #
1224
1335
  # The default is 60 seconds.
1225
1336
  #
@@ -1277,23 +1388,28 @@ module Puma
1277
1388
  @options[:worker_culling_strategy] = strategy
1278
1389
  end
1279
1390
 
1280
- # When set to true, workers accept all requests
1281
- # and queue them before passing them to the handlers.
1282
- # When set to false, each worker process accepts exactly as
1283
- # many requests as it is configured to simultaneously handle.
1391
+ # When `true`, a worker thread that receives a client with an
1392
+ # incomplete request body hands the client to a Reactor thread
1393
+ # and returns to the pool. The Reactor re-enqueues the client
1394
+ # once the body has been received. This frees workers from
1395
+ # blocking on slow client sends and enables HTTP keep-alive. A
1396
+ # worker must still receive each client first, so this does
1397
+ # not queue new connections when the pool is saturated.
1284
1398
  #
1285
- # Queueing requests generally improves performance. In some
1286
- # cases, such as a single threaded application, it may be
1287
- # better to ensure requests get balanced across workers.
1288
- #
1289
- # Note that setting this to false disables HTTP keepalive and
1290
- # slow clients will occupy a handler thread while the request
1291
- # is being sent. A reverse proxy, such as nginx, can handle
1292
- # slow clients and queue requests before they reach Puma.
1399
+ # When `false`, no Reactor runs. A worker thread reads each
1400
+ # request synchronously and remains occupied for the duration
1401
+ # of the client's request send, and HTTP keep-alive is
1402
+ # disabled. Consider running Puma behind a reverse proxy such
1403
+ # as nginx that can buffer requests and protect Puma from slow
1404
+ # clients.
1293
1405
  #
1294
1406
  # The default is +true+.
1295
1407
  #
1408
+ # @example
1409
+ # queue_requests false
1410
+ #
1296
1411
  # @see Puma::Server
1412
+ # @see Puma::Reactor
1297
1413
  #
1298
1414
  def queue_requests(answer=true)
1299
1415
  @options[:queue_requests] = answer
@@ -1306,7 +1422,13 @@ module Puma
1306
1422
  # If `on_force` is true, the backtraces will be written only
1307
1423
  # when the shutdown is forced i.e. not graceful.
1308
1424
  #
1425
+ # The default is +nil+.
1426
+ #
1427
+ # @example
1428
+ # shutdown_debug
1429
+ #
1309
1430
  # @see force_shutdown_after
1431
+ #
1310
1432
  def shutdown_debug(val = true, on_force: false)
1311
1433
  @options[:shutdown_debug] = val && on_force ? :on_force : val
1312
1434
  end
@@ -1354,7 +1476,7 @@ module Puma
1354
1476
  # HAproxy PROXY protocol, version 1. If the request does not have the PROXY
1355
1477
  # protocol attached to it, will fall back to :socket
1356
1478
  # 5. **\<Any string\>** - this allows you to hardcode remote address to any value
1357
- # you wish. Because Puma never uses this field anyway, it's format is
1479
+ # you wish. Because Puma never uses this field anyway, its format is
1358
1480
  # entirely in your hands.
1359
1481
  #
1360
1482
  # The default is +:socket+.
@@ -1393,7 +1515,7 @@ module Puma
1393
1515
 
1394
1516
  # When enabled, workers will be forked from worker 0 instead of from the master process.
1395
1517
  # This option is similar to `preload_app` because the app is preloaded before forking,
1396
- # but it is compatible with phased restart.
1518
+ # but it is compatible with phased restart when `preload_app!` is disabled.
1397
1519
  #
1398
1520
  # This option also enables the `refork` command (SIGURG), which optimizes copy-on-write performance
1399
1521
  # in a running app.
@@ -1401,13 +1523,41 @@ module Puma
1401
1523
  # A refork will automatically trigger once after the specified number of requests
1402
1524
  # (default 1000), or pass 0 to disable auto refork.
1403
1525
  #
1526
+ # The default is +nil+.
1527
+ #
1404
1528
  # @note This is experimental.
1405
1529
  # @note Cluster mode only.
1406
1530
  #
1531
+ # @example
1532
+ # fork_worker
1533
+ #
1407
1534
  def fork_worker(after_requests=1000)
1408
1535
  @options[:fork_worker] = Integer(after_requests)
1409
1536
  end
1410
1537
 
1538
+ # When enabled, a worker that reaches the given request count stops serving
1539
+ # requests and becomes a "mold", a template process that every new worker
1540
+ # is forked from. Each threshold promotes a new mold and reforks all workers
1541
+ # from it. Thresholds are per worker, counted from when that worker booted.
1542
+ #
1543
+ # This option also enables the `refork` command (SIGURG), which promotes
1544
+ # the busiest worker to a new mold at any time.
1545
+ #
1546
+ # Incompatible with `fork_worker`.
1547
+ #
1548
+ # The default is +nil+.
1549
+ #
1550
+ # @note This is experimental.
1551
+ # @note Cluster mode only.
1552
+ #
1553
+ # @example
1554
+ # mold_worker 1000, 2000, 4000
1555
+ #
1556
+ def mold_worker(*thresholds)
1557
+ thresholds = [1000] if thresholds.empty?
1558
+ @options[:mold_worker] = thresholds.map { |t| Integer(t) }
1559
+ end
1560
+
1411
1561
  # @deprecated Use {#max_keep_alive} instead.
1412
1562
  #
1413
1563
  def max_fast_inline(num_of_requests)
@@ -1417,13 +1567,15 @@ module Puma
1417
1567
 
1418
1568
  # The number of requests a keep-alive client can submit before being closed.
1419
1569
  # Note that some applications (server to server) may benefit from a very high
1420
- # number or Float::INFINITY.
1570
+ # number or +Float::INFINITY+.
1421
1571
  #
1422
- # The default is 999.
1572
+ # The default is +999+.
1423
1573
  #
1424
1574
  # @example
1425
1575
  # max_keep_alive 20
1426
1576
  #
1577
+ # @see enable_keep_alives
1578
+ #
1427
1579
  def max_keep_alive(num_of_requests)
1428
1580
  @options[:max_keep_alive] = Float(num_of_requests) unless num_of_requests.nil?
1429
1581
  end
@@ -1454,6 +1606,25 @@ module Puma
1454
1606
  @options[:enable_keep_alives] = enabled
1455
1607
  end
1456
1608
 
1609
+ # When +false+, request headers with underscores in their names are discarded.
1610
+ # When such headers are present, their names are exposed in
1611
+ # +env["puma.underscore_headers"]+ for auditing. This value is
1612
+ # client-triggerable, so rate-limit or sample external reporting.
1613
+ #
1614
+ # Requests containing +Content_Length+ or +Transfer_Encoding+ are always
1615
+ # rejected with 400 and the connection is closed, regardless of this option.
1616
+ # Clients must use the standard +Content-Length+ and +Transfer-Encoding+ names.
1617
+ #
1618
+ # The default is +true+, but will change to +false+ in a future major
1619
+ # version, when this env metadata will be removed.
1620
+ #
1621
+ # @example
1622
+ # allow_underscore_headers false
1623
+ #
1624
+ def allow_underscore_headers(allowed=true)
1625
+ @options[:allow_underscore_headers] = allowed
1626
+ end
1627
+
1457
1628
  # Specify the backend for the IO selector.
1458
1629
  #
1459
1630
  # Provided values will be passed directly to +NIO::Selector.new+, with the
@@ -1467,14 +1638,17 @@ module Puma
1467
1638
  #
1468
1639
  # The default is +:auto+.
1469
1640
  #
1641
+ # @example
1642
+ # io_selector_backend :epoll
1643
+ #
1470
1644
  # @see https://github.com/socketry/nio4r/blob/main/lib/nio/selector.rb
1471
1645
  #
1472
1646
  def io_selector_backend(backend)
1473
1647
  @options[:io_selector_backend] = backend.to_sym
1474
1648
  end
1475
1649
 
1476
- # Ensures +STDOUT+ and +STDERR+ is immediately flushed to the underlying
1477
- # operating system and is not buffered internally
1650
+ # Ensures +STDOUT+ and +STDERR+ are immediately flushed to the underlying
1651
+ # operating system and are not buffered internally.
1478
1652
  #
1479
1653
  # The default is +true+.
1480
1654
  #
@@ -1485,13 +1659,13 @@ module Puma
1485
1659
  @options[:mutate_stdout_and_stderr_to_sync_on_write] = enabled
1486
1660
  end
1487
1661
 
1488
- # Specify how big the request payload should be, in bytes.
1489
- # This limit is compared against Content-Length HTTP header.
1490
- # If the payload size (CONTENT_LENGTH) is larger than http_content_length_limit,
1491
- # HTTP 413 status code is returned.
1662
+ # Specify the maximum request payload size, in bytes. If the value of
1663
+ # the +Content-Length+ header exceeds this limit, an HTTP 413 status
1664
+ # code is returned.
1492
1665
  #
1493
- # When no Content-Length http header is present, it is compared against the
1494
- # size of the body of the request.
1666
+ # This limit is only applicable when the client sends a `Content-Length`
1667
+ # header, or `Transfer-Encoding` is `chunked`. Otherwise there is no
1668
+ # request body.
1495
1669
  #
1496
1670
  # The default is +nil+.
1497
1671
  #
@@ -1503,15 +1677,15 @@ module Puma
1503
1677
  end
1504
1678
 
1505
1679
  # Supported http methods, which will replace `Puma::Const::SUPPORTED_HTTP_METHODS`.
1506
- # The value of `:any` will allows all methods, otherwise, the value must be
1507
- # an array of strings. Note that methods are all uppercase.
1680
+ # The value of `:any` will allow all methods, otherwise, the value must be
1681
+ # an array of strings. Note that methods are all uppercase.
1508
1682
  #
1509
1683
  # `Puma::Const::SUPPORTED_HTTP_METHODS` is conservative, if you want a
1510
1684
  # complete set of methods, the methods defined by the
1511
1685
  # [IANA Method Registry](https://www.iana.org/assignments/http-methods/http-methods.xhtml)
1512
1686
  # are pre-defined as the constant `Puma::Const::IANA_HTTP_METHODS`.
1513
1687
  #
1514
- # @note If the `methods` value is `:any`, no method check with be performed,
1688
+ # @note If the `methods` value is `:any`, no method check will be performed,
1515
1689
  # similar to Puma v5 and earlier.
1516
1690
  #
1517
1691
  # @example Adds 'PROPFIND' to existing supported methods