ed-precompiled_puma 7.0.4

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 (88) hide show
  1. checksums.yaml +7 -0
  2. data/History.md +3172 -0
  3. data/LICENSE +29 -0
  4. data/README.md +477 -0
  5. data/bin/puma +10 -0
  6. data/bin/puma-wild +25 -0
  7. data/bin/pumactl +12 -0
  8. data/docs/architecture.md +74 -0
  9. data/docs/compile_options.md +55 -0
  10. data/docs/deployment.md +102 -0
  11. data/docs/fork_worker.md +41 -0
  12. data/docs/images/puma-connection-flow-no-reactor.png +0 -0
  13. data/docs/images/puma-connection-flow.png +0 -0
  14. data/docs/images/puma-general-arch.png +0 -0
  15. data/docs/java_options.md +54 -0
  16. data/docs/jungle/README.md +9 -0
  17. data/docs/jungle/rc.d/README.md +74 -0
  18. data/docs/jungle/rc.d/puma +61 -0
  19. data/docs/jungle/rc.d/puma.conf +10 -0
  20. data/docs/kubernetes.md +80 -0
  21. data/docs/nginx.md +80 -0
  22. data/docs/plugins.md +42 -0
  23. data/docs/rails_dev_mode.md +28 -0
  24. data/docs/restart.md +65 -0
  25. data/docs/signals.md +98 -0
  26. data/docs/stats.md +148 -0
  27. data/docs/systemd.md +253 -0
  28. data/docs/testing_benchmarks_local_files.md +150 -0
  29. data/docs/testing_test_rackup_ci_files.md +36 -0
  30. data/ext/puma_http11/PumaHttp11Service.java +17 -0
  31. data/ext/puma_http11/ext_help.h +15 -0
  32. data/ext/puma_http11/extconf.rb +65 -0
  33. data/ext/puma_http11/http11_parser.c +1057 -0
  34. data/ext/puma_http11/http11_parser.h +65 -0
  35. data/ext/puma_http11/http11_parser.java.rl +145 -0
  36. data/ext/puma_http11/http11_parser.rl +149 -0
  37. data/ext/puma_http11/http11_parser_common.rl +54 -0
  38. data/ext/puma_http11/mini_ssl.c +852 -0
  39. data/ext/puma_http11/no_ssl/PumaHttp11Service.java +15 -0
  40. data/ext/puma_http11/org/jruby/puma/Http11.java +257 -0
  41. data/ext/puma_http11/org/jruby/puma/Http11Parser.java +455 -0
  42. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +509 -0
  43. data/ext/puma_http11/puma_http11.c +507 -0
  44. data/lib/puma/app/status.rb +96 -0
  45. data/lib/puma/binder.rb +511 -0
  46. data/lib/puma/cli.rb +245 -0
  47. data/lib/puma/client.rb +720 -0
  48. data/lib/puma/cluster/worker.rb +182 -0
  49. data/lib/puma/cluster/worker_handle.rb +127 -0
  50. data/lib/puma/cluster.rb +635 -0
  51. data/lib/puma/cluster_accept_loop_delay.rb +91 -0
  52. data/lib/puma/commonlogger.rb +115 -0
  53. data/lib/puma/configuration.rb +452 -0
  54. data/lib/puma/const.rb +307 -0
  55. data/lib/puma/control_cli.rb +320 -0
  56. data/lib/puma/detect.rb +47 -0
  57. data/lib/puma/dsl.rb +1480 -0
  58. data/lib/puma/error_logger.rb +115 -0
  59. data/lib/puma/events.rb +72 -0
  60. data/lib/puma/io_buffer.rb +50 -0
  61. data/lib/puma/jruby_restart.rb +11 -0
  62. data/lib/puma/json_serialization.rb +96 -0
  63. data/lib/puma/launcher/bundle_pruner.rb +104 -0
  64. data/lib/puma/launcher.rb +496 -0
  65. data/lib/puma/log_writer.rb +147 -0
  66. data/lib/puma/minissl/context_builder.rb +96 -0
  67. data/lib/puma/minissl.rb +463 -0
  68. data/lib/puma/null_io.rb +101 -0
  69. data/lib/puma/plugin/systemd.rb +90 -0
  70. data/lib/puma/plugin/tmp_restart.rb +36 -0
  71. data/lib/puma/plugin.rb +111 -0
  72. data/lib/puma/rack/builder.rb +297 -0
  73. data/lib/puma/rack/urlmap.rb +93 -0
  74. data/lib/puma/rack_default.rb +24 -0
  75. data/lib/puma/reactor.rb +140 -0
  76. data/lib/puma/request.rb +701 -0
  77. data/lib/puma/runner.rb +211 -0
  78. data/lib/puma/sd_notify.rb +146 -0
  79. data/lib/puma/server.rb +734 -0
  80. data/lib/puma/single.rb +72 -0
  81. data/lib/puma/state_file.rb +69 -0
  82. data/lib/puma/thread_pool.rb +402 -0
  83. data/lib/puma/util.rb +134 -0
  84. data/lib/puma.rb +93 -0
  85. data/lib/rack/handler/puma.rb +144 -0
  86. data/tools/Dockerfile +18 -0
  87. data/tools/trickletest.rb +44 -0
  88. metadata +152 -0
@@ -0,0 +1,182 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Puma
4
+ class Cluster < Puma::Runner
5
+ #—————————————————————— DO NOT USE — this class is for internal use only ———
6
+
7
+
8
+ # This class is instantiated by the `Puma::Cluster` and represents a single
9
+ # worker process.
10
+ #
11
+ # At the core of this class is running an instance of `Puma::Server` which
12
+ # gets created via the `start_server` method from the `Puma::Runner` class
13
+ # that this inherits from.
14
+ class Worker < Puma::Runner # :nodoc:
15
+ attr_reader :index, :master
16
+
17
+ def initialize(index:, master:, launcher:, pipes:, server: nil)
18
+ super(launcher)
19
+
20
+ @index = index
21
+ @master = master
22
+ @check_pipe = pipes[:check_pipe]
23
+ @worker_write = pipes[:worker_write]
24
+ @fork_pipe = pipes[:fork_pipe]
25
+ @wakeup = pipes[:wakeup]
26
+ @server = server
27
+ @hook_data = {}
28
+ end
29
+
30
+ def run
31
+ title = "puma: cluster worker #{index}: #{master}"
32
+ title += " [#{@options[:tag]}]" if @options[:tag] && !@options[:tag].empty?
33
+ $0 = title
34
+
35
+ Signal.trap "SIGINT", "IGNORE"
36
+ Signal.trap "SIGCHLD", "DEFAULT"
37
+
38
+ Thread.new do
39
+ Puma.set_thread_name "wrkr check"
40
+ @check_pipe.wait_readable
41
+ log "! Detected parent died, dying"
42
+ exit! 1
43
+ end
44
+
45
+ # If we're not running under a Bundler context, then
46
+ # report the info about the context we will be using
47
+ if !ENV['BUNDLE_GEMFILE']
48
+ if File.exist?("Gemfile")
49
+ log "+ Gemfile in context: #{File.expand_path("Gemfile")}"
50
+ elsif File.exist?("gems.rb")
51
+ log "+ Gemfile in context: #{File.expand_path("gems.rb")}"
52
+ end
53
+ end
54
+
55
+ # Invoke any worker boot hooks so they can get
56
+ # things in shape before booting the app.
57
+ @config.run_hooks(:before_worker_boot, index, @log_writer, @hook_data)
58
+
59
+ begin
60
+ server = @server ||= start_server
61
+ rescue Exception => e
62
+ log "! Unable to start worker"
63
+ log e
64
+ log e.backtrace.join("\n ")
65
+ exit 1
66
+ end
67
+
68
+ restart_server = Queue.new << true << false
69
+
70
+ fork_worker = @options[:fork_worker] && index == 0
71
+
72
+ if fork_worker
73
+ restart_server.clear
74
+ worker_pids = []
75
+ Signal.trap "SIGCHLD" do
76
+ wakeup! if worker_pids.reject! do |p|
77
+ Process.wait(p, Process::WNOHANG) rescue true
78
+ end
79
+ end
80
+
81
+ Thread.new do
82
+ Puma.set_thread_name "wrkr fork"
83
+ while (idx = @fork_pipe.gets)
84
+ idx = idx.to_i
85
+ if idx == -1 # stop server
86
+ if restart_server.length > 0
87
+ restart_server.clear
88
+ server.begin_restart(true)
89
+ @config.run_hooks(:before_refork, nil, @log_writer, @hook_data)
90
+ end
91
+ elsif idx == -2 # refork cycle is done
92
+ @config.run_hooks(:after_refork, nil, @log_writer, @hook_data)
93
+ elsif idx == 0 # restart server
94
+ restart_server << true << false
95
+ else # fork worker
96
+ worker_pids << pid = spawn_worker(idx)
97
+ @worker_write << "#{PIPE_FORK}#{pid}:#{idx}\n" rescue nil
98
+ end
99
+ end
100
+ end
101
+ end
102
+
103
+ Signal.trap "SIGTERM" do
104
+ @worker_write << "#{PIPE_EXTERNAL_TERM}#{Process.pid}\n" rescue nil
105
+ restart_server.clear
106
+ server.stop
107
+ restart_server << false
108
+ end
109
+
110
+ begin
111
+ @worker_write << "#{PIPE_BOOT}#{Process.pid}:#{index}\n"
112
+ rescue SystemCallError, IOError
113
+ STDERR.puts "Master seems to have exited, exiting."
114
+ return
115
+ end
116
+
117
+ while restart_server.pop
118
+ server_thread = server.run
119
+
120
+ if @log_writer.debug? && index == 0
121
+ debug_loaded_extensions "Loaded Extensions - worker 0:"
122
+ end
123
+
124
+ stat_thread ||= Thread.new(@worker_write) do |io|
125
+ Puma.set_thread_name "stat pld"
126
+ base_payload = "#{PIPE_PING}#{Process.pid}"
127
+
128
+ while true
129
+ begin
130
+ payload = base_payload.dup
131
+
132
+ hsh = server.stats
133
+ hsh.each do |k, v|
134
+ payload << %Q! "#{k}":#{v || 0},!
135
+ end
136
+ # sub call properly adds 'closing' string
137
+ io << payload.sub(/,\z/, " }\n")
138
+ server.reset_max
139
+ rescue IOError
140
+ break
141
+ end
142
+ sleep @options[:worker_check_interval]
143
+ end
144
+ end
145
+ server_thread.join
146
+ end
147
+
148
+ # Invoke any worker shutdown hooks so they can prevent the worker
149
+ # exiting until any background operations are completed
150
+ @config.run_hooks(:before_worker_shutdown, index, @log_writer, @hook_data)
151
+ ensure
152
+ @worker_write << "#{PIPE_TERM}#{Process.pid}\n" rescue nil
153
+ @worker_write.close
154
+ end
155
+
156
+ private
157
+
158
+ def spawn_worker(idx)
159
+ @config.run_hooks(:before_worker_fork, idx, @log_writer, @hook_data)
160
+
161
+ pid = fork do
162
+ new_worker = Worker.new index: idx,
163
+ master: master,
164
+ launcher: @launcher,
165
+ pipes: { check_pipe: @check_pipe,
166
+ worker_write: @worker_write },
167
+ server: @server
168
+ new_worker.run
169
+ end
170
+
171
+ if !pid
172
+ log "! Complete inability to spawn new workers detected"
173
+ log "! Seppuku is the only choice."
174
+ exit! 1
175
+ end
176
+
177
+ @config.run_hooks(:after_worker_fork, idx, @log_writer, @hook_data)
178
+ pid
179
+ end
180
+ end
181
+ end
182
+ end
@@ -0,0 +1,127 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Puma
4
+ class Cluster < Runner
5
+ #—————————————————————— DO NOT USE — this class is for internal use only ———
6
+
7
+ # This class represents a worker process from the perspective of the puma
8
+ # master process. It contains information about the process and its health
9
+ # and it exposes methods to control the process via IPC. It does not
10
+ # include the actual logic executed by the worker process itself. For that,
11
+ # see Puma::Cluster::Worker.
12
+ class WorkerHandle # :nodoc:
13
+ # array of stat 'max' keys
14
+ WORKER_MAX_KEYS = [:backlog_max, :reactor_max]
15
+
16
+ def initialize(idx, pid, phase, options)
17
+ @index = idx
18
+ @pid = pid
19
+ @phase = phase
20
+ @stage = :started
21
+ @signal = "TERM"
22
+ @options = options
23
+ @first_term_sent = nil
24
+ @started_at = Time.now
25
+ @last_checkin = Time.now
26
+ @last_status = {}
27
+ @term = false
28
+ @worker_max = Array.new WORKER_MAX_KEYS.length, 0
29
+ end
30
+
31
+ attr_reader :index, :pid, :phase, :signal, :last_checkin, :last_status, :started_at, :process_status
32
+
33
+ # @version 5.0.0
34
+ attr_writer :pid, :phase, :process_status
35
+
36
+ def booted?
37
+ @stage == :booted
38
+ end
39
+
40
+ def uptime
41
+ Time.now - started_at
42
+ end
43
+
44
+ def boot!
45
+ @last_checkin = Time.now
46
+ @stage = :booted
47
+ end
48
+
49
+ def term!
50
+ @term = true
51
+ end
52
+
53
+ def term?
54
+ @term
55
+ end
56
+
57
+ def ping!(status)
58
+ hsh = {}
59
+ k, v = nil, nil
60
+ status.tr('}{"', '').strip.split(", ") do |kv|
61
+ cntr = 0
62
+ kv.split(':') do |t|
63
+ if cntr == 0
64
+ k = t
65
+ cntr = 1
66
+ else
67
+ v = t
68
+ end
69
+ end
70
+ hsh[k.to_sym] = v.to_i
71
+ end
72
+
73
+ # check stat max values, we can't signal workers to reset the max values,
74
+ # so we do so here
75
+ WORKER_MAX_KEYS.each_with_index do |key, idx|
76
+ next unless hsh[key]
77
+
78
+ if hsh[key] < @worker_max[idx]
79
+ hsh[key] = @worker_max[idx]
80
+ else
81
+ @worker_max[idx] = hsh[key]
82
+ end
83
+ end
84
+ @last_checkin = Time.now
85
+ @last_status = hsh
86
+ end
87
+
88
+ # Resets max values to zero. Called whenever `Cluster#stats` is called
89
+ def reset_max
90
+ WORKER_MAX_KEYS.length.times { |idx| @worker_max[idx] = 0 }
91
+ end
92
+
93
+ # @see Puma::Cluster#check_workers
94
+ # @version 5.0.0
95
+ def ping_timeout
96
+ @last_checkin +
97
+ (booted? ?
98
+ @options[:worker_timeout] :
99
+ @options[:worker_boot_timeout]
100
+ )
101
+ end
102
+
103
+ def term
104
+ begin
105
+ if @first_term_sent && (Time.now - @first_term_sent) > @options[:worker_shutdown_timeout]
106
+ @signal = "KILL"
107
+ else
108
+ @term ||= true
109
+ @first_term_sent ||= Time.now
110
+ end
111
+ Process.kill @signal, @pid if @pid
112
+ rescue Errno::ESRCH
113
+ end
114
+ end
115
+
116
+ def kill
117
+ @signal = 'KILL'
118
+ term
119
+ end
120
+
121
+ def hup
122
+ Process.kill "HUP", @pid
123
+ rescue Errno::ESRCH
124
+ end
125
+ end
126
+ end
127
+ end