<NME> puma.rb.erb
<BEF> # frozen_string_literal: true

# This file is managed by gitlab-ctl. Manual changes will be
# erased! To change the contents below, edit /etc/gitlab/gitlab.rb
# and run `sudo gitlab-ctl reconfigure`.

# Load "path" as a rackup file.
#
# The default is "config.ru".
#
environment '<%= @environment %>'
rackup '<%= @install_dir %>/embedded/service/gitlab-rails/<%= @rackup %>'
pidfile '<%= @pid %>'
state_path '<%= @state_path %>'

stdout_redirect '<%= @stdout_path %>', '<%= @stderr_path %>', true

# Configure "min" to be the minimum number of threads to use to answer
# requests and "max" the maximum.
#
# The default is "0, 16".
#
threads <%= @min_threads %>, <%= @max_threads %>

# By default, workers accept all requests and queue them to pass to handlers.
# When false, workers accept the number of simultaneous requests configured.
#
# Queueing requests generally improves performance, but can cause deadlocks if
# the app is waiting on a request to itself. See https://github.com/puma/puma/issues/612
#
# When set to false this may require a reverse proxy to handle slow clients and
# queue requests before they reach puma. This is due to disabling HTTP keepalive
queue_requests false

# Bind the server to "url". "tcp://", "unix://" and "ssl://" are the only
# accepted protocols.
<%- if @listen_socket && !@listen_socket.empty? %>
bind 'unix://<%= @listen_socket %>'
<%- end %>

<%- if @listen_tcp %>
bind 'tcp://<%= @listen_tcp %>'
<%- end %>

<%- if @ssl_listen_host && @ssl_port %>
ssl_bind '<%= @ssl_listen_host %>', <%= @ssl_port %>, {
  <%- if @ssl_certificate %>
  cert: '<%= @ssl_certificate %>',
  <%- end %>
  <%- if @ssl_certificate_key %>
  key: '<%= @ssl_certificate_key %>',
  <%- end %>
  <%- if @ssl_client_certificate %>
  ca: '<%= @ssl_client_certificate %>',
  <%- end %>
  <%- if @ssl_cipher_filter %>
  ssl_cipher_filter: '<%= @ssl_cipher_filter %>',
  <%- end %>
  <%- if @ssl_verify_mode %>
  verify_mode: '<%= @ssl_verify_mode %>'
  <%- end %>
}
<%- end %>

<%- if @working_directory %>
directory '<%= @working_directory %>'
<%- end %>

workers <%= @worker_processes %>

require_relative "<%= @install_dir %>/embedded/service/gitlab-rails/lib/gitlab/cluster/lifecycle_events"
require_relative "<%= @install_dir %>/embedded/service/gitlab-rails/lib/gitlab/cluster/puma_worker_killer_initializer"

on_restart do
  # Signal application hooks that we're about to restart
  Gitlab::Cluster::LifecycleEvents.do_before_master_restart
end

options = { workers: <%= @worker_processes %> }

before_fork do
  enable_puma_worker_killer = !Gitlab::Utils.to_boolean(ENV['DISABLE_PUMA_WORKER_KILLER'])
  Gitlab::Cluster::PumaWorkerKillerInitializer.start(options<% unless @per_worker_max_memory_mb.nil? %>, puma_per_worker_max_memory_mb: <%= @per_worker_max_memory_mb %><% end %>) if enable_puma_worker_killer

  # Signal application hooks that we're about to fork
  Gitlab::Cluster::LifecycleEvents.do_before_fork
end

Gitlab::Cluster::LifecycleEvents.set_puma_options options
on_worker_boot do
  # Signal application hooks of worker start

# https://github.com/puma/puma/blob/master/5.0-Upgrade.md#nakayoshi_fork
if defined?(nakayoshi_fork)
  nakayoshi_fork unless ENV['DISABLE_PUMA_NAKAYOSHI_FORK'] == 'true'
end

# Use customised JSON formatter for Puma log

tag '<%= @tag %>'

# Verifies that all workers have checked in to the master process within
# the given timeout. If not the worker process will be restarted. Default
# value is 60 seconds.
#
worker_timeout <%= @worker_timeout %>

# https://github.com/puma/puma/blob/master/5.0-Upgrade.md#lower-latency-better-throughput
wait_for_less_busy_worker ENV.fetch('PUMA_WAIT_FOR_LESS_BUSY_WORKER', 0.001).to_f

# https://github.com/puma/puma/blob/master/5.0-Upgrade.md#nakayoshi_fork
nakayoshi_fork unless ENV['DISABLE_PUMA_NAKAYOSHI_FORK'] == 'true'

# Use customised JSON formatter for Puma log
require_relative "<%= @install_dir %>/embedded/service/gitlab-rails/lib/gitlab/puma_logging/json_formatter"

json_formatter = Gitlab::PumaLogging::JSONFormatter.new
log_formatter do |str|
    json_formatter.call(str)
end

lowlevel_error_handler do |ex, env|
  if Raven.configuration.capture_allowed?
    Raven.capture_exception(ex, tags: { 'handler': 'puma_low_level' }, extra: { puma_env: env })
  end

  # note the below is just a Rack response
  [500, {}, ["An error has occurred and reported in the system's low-level error handler."]]
end

<MSG> Disable nakayoshi_fork by default

This a precautionary step to see if this prevents a seg fault at boot:
https://gitlab.com/gitlab-com/gl-infra/production/-/issues/3370

<DFF> @@ -92,7 +92,7 @@ end
 
 # https://github.com/puma/puma/blob/master/5.0-Upgrade.md#nakayoshi_fork
 if defined?(nakayoshi_fork)
-  nakayoshi_fork unless ENV['DISABLE_PUMA_NAKAYOSHI_FORK'] == 'true'
+  nakayoshi_fork if ENV['ENABLE_PUMA_NAKAYOSHI_FORK'] == 'true'
 end
 
 # Use customised JSON formatter for Puma log

{'commit': "diff --git a/files/gitlab-cookbooks/gitlab/templates/default/puma.rb.erb b/files/gitlab-cookbooks/gitlab/templates/default/puma.rb.erb\nindex 0ded3475a..b6d474203 100644\n--- a/files/gitlab-cookbooks/gitlab/templates/default/puma.rb.erb\n+++ b/files/gitlab-cookbooks/gitlab/templates/default/puma.rb.erb\n@@ -92,7 +92,7 @@ end\n \n # https://github.com/puma/puma/blob/master/5.0-Upgrade.md#nakayoshi_fork\n if defined?(nakayoshi_fork)\n-  nakayoshi_fork unless ENV['DISABLE_PUMA_NAKAYOSHI_FORK'] == 'true'\n+  nakayoshi_fork if ENV['ENABLE_PUMA_NAKAYOSHI_FORK'] == 'true'\n end\n \n # Use customised JSON formatter for Puma log\n", 'commit_subject': 'Disable nakayoshi_fork by default', 'repo_name': 'gitlabhq/omnibus-gitlab', 'committer': {'name': 'Stan Hu', 'email': '1b75cc461044b78a759f097fe82a64cb6f58b890@gmail.com', 'time_sec': '1611094663', 'tz_offset': '-480', 'date': {'seconds': '1611094663'}}, 'commit_tree': '594eb9ab627406d0cd58c1aebe1a9711b3f04641', 'commit_message': 'Disable nakayoshi_fork by default\n\nThis a precautionary step to see if this prevents a seg fault at boot:\nhttps://gitlab.com/gitlab-com/gl-infra/production/-/issues/3370\n', 'language_name': 'Ruby', 'license': 'apache-2.0', 'hunks': "@@ -92,7 +92,7 @@ end\n \n # https://github.com/puma/puma/blob/master/5.0-Upgrade.md#nakayoshi_fork\n if defined?(nakayoshi_fork)\n-  nakayoshi_fork unless ENV['DISABLE_PUMA_NAKAYOSHI_FORK'] == 'true'\n+  nakayoshi_fork if ENV['ENABLE_PUMA_NAKAYOSHI_FORK'] == 'true'\n end\n \n # Use customised JSON formatter for Puma log\n", 'addition_count': 1, 'deletion_count': 1, 'src_file': 'a/files/gitlab-cookbooks/gitlab/templates/default/puma.rb.erb', 'tgt_file': 'b/files/gitlab-cookbooks/gitlab/templates/default/puma.rb.erb', 'file_extension': '.erb', 'before_file': '# frozen_string_literal: true\n\n# This file is managed by gitlab-ctl. Manual changes will be\n# erased! To change the contents below, edit /etc/gitlab/gitlab.rb\n# and run `sudo gitlab-ctl reconfigure`.\n\n# Load "path" as a rackup file.\n#\n# The default is "config.ru".\n#\nenvironment \'<%= @environment %>\'\nrackup \'<%= @install_dir %>/embedded/service/gitlab-rails/<%= @rackup %>\'\npidfile \'<%= @pid %>\'\nstate_path \'<%= @state_path %>\'\n\nstdout_redirect \'<%= @stdout_path %>\', \'<%= @stderr_path %>\', true\n\n# Configure "min" to be the minimum number of threads to use to answer\n# requests and "max" the maximum.\n#\n# The default is "0, 16".\n#\nthreads <%= @min_threads %>, <%= @max_threads %>\n\n# By default, workers accept all requests and queue them to pass to handlers.\n# When false, workers accept the number of simultaneous requests configured.\n#\n# Queueing requests generally improves performance, but can cause deadlocks if\n# the app is waiting on a request to itself. See https://github.com/puma/puma/issues/612\n#\n# When set to false this may require a reverse proxy to handle slow clients and\n# queue requests before they reach puma. This is due to disabling HTTP keepalive\nqueue_requests false\n\n# Bind the server to "url". "tcp://", "unix://" and "ssl://" are the only\n# accepted protocols.\n<%- if @listen_socket && !@listen_socket.empty? %>\nbind \'unix://<%= @listen_socket %>\'\n<%- end %>\n\n<%- if @listen_tcp %>\nbind \'tcp://<%= @listen_tcp %>\'\n<%- end %>\n\n<%- if @ssl_listen_host && @ssl_port %>\nssl_bind \'<%= @ssl_listen_host %>\', <%= @ssl_port %>, {\n  <%- if @ssl_certificate %>\n  cert: \'<%= @ssl_certificate %>\',\n  <%- end %>\n  <%- if @ssl_certificate_key %>\n  key: \'<%= @ssl_certificate_key %>\',\n  <%- end %>\n  <%- if @ssl_client_certificate %>\n  ca: \'<%= @ssl_client_certificate %>\',\n  <%- end %>\n  <%- if @ssl_cipher_filter %>\n  ssl_cipher_filter: \'<%= @ssl_cipher_filter %>\',\n  <%- end %>\n  <%- if @ssl_verify_mode %>\n  verify_mode: \'<%= @ssl_verify_mode %>\'\n  <%- end %>\n}\n<%- end %>\n\n<%- if @working_directory %>\ndirectory \'<%= @working_directory %>\'\n<%- end %>\n\nworkers <%= @worker_processes %>\n\nrequire_relative "<%= @install_dir %>/embedded/service/gitlab-rails/lib/gitlab/cluster/lifecycle_events"\nrequire_relative "<%= @install_dir %>/embedded/service/gitlab-rails/lib/gitlab/cluster/puma_worker_killer_initializer"\n\non_restart do\n  # Signal application hooks that we\'re about to restart\n  Gitlab::Cluster::LifecycleEvents.do_before_master_restart\nend\n\noptions = { workers: <%= @worker_processes %> }\n\nbefore_fork do\n  enable_puma_worker_killer = !Gitlab::Utils.to_boolean(ENV[\'DISABLE_PUMA_WORKER_KILLER\'])\n  Gitlab::Cluster::PumaWorkerKillerInitializer.start(options<% unless @per_worker_max_memory_mb.nil? %>, puma_per_worker_max_memory_mb: <%= @per_worker_max_memory_mb %><% end %>) if enable_puma_worker_killer\n\n  # Signal application hooks that we\'re about to fork\n  Gitlab::Cluster::LifecycleEvents.do_before_fork\nend\n\nGitlab::Cluster::LifecycleEvents.set_puma_options options\non_worker_boot do\n  # Signal application hooks of worker start\n\n# https://github.com/puma/puma/blob/master/5.0-Upgrade.md#nakayoshi_fork\nif defined?(nakayoshi_fork)\n  nakayoshi_fork unless ENV[\'DISABLE_PUMA_NAKAYOSHI_FORK\'] == \'true\'\nend\n\n# Use customised JSON formatter for Puma log\n\ntag \'<%= @tag %>\'\n\n# Verifies that all workers have checked in to the master process within\n# the given timeout. If not the worker process will be restarted. Default\n# value is 60 seconds.\n#\nworker_timeout <%= @worker_timeout %>\n\n# https://github.com/puma/puma/blob/master/5.0-Upgrade.md#lower-latency-better-throughput\nwait_for_less_busy_worker ENV.fetch(\'PUMA_WAIT_FOR_LESS_BUSY_WORKER\', 0.001).to_f\n\n# https://github.com/puma/puma/blob/master/5.0-Upgrade.md#nakayoshi_fork\nnakayoshi_fork unless ENV[\'DISABLE_PUMA_NAKAYOSHI_FORK\'] == \'true\'\n\n# Use customised JSON formatter for Puma log\nrequire_relative "<%= @install_dir %>/embedded/service/gitlab-rails/lib/gitlab/puma_logging/json_formatter"\n\njson_formatter = Gitlab::PumaLogging::JSONFormatter.new\nlog_formatter do |str|\n    json_formatter.call(str)\nend\n\nlowlevel_error_handler do |ex, env|\n  if Raven.configuration.capture_allowed?\n    Raven.capture_exception(ex, tags: { \'handler\': \'puma_low_level\' }, extra: { puma_env: env })\n  end\n\n  # note the below is just a Rack response\n  [500, {}, ["An error has occurred and reported in the system\'s low-level error handler."]]\nend\n', 'message': 'Disable nakayoshi_fork by default\n\nThis a precautionary step to see if this prevents a seg fault at boot:\nhttps://gitlab.com/gitlab-com/gl-infra/production/-/issues/3370\n', 'author_name': 'Stan Hu', 'lang': 'rb'}