gitlab-org--gitlab-foss/config/initializers/rack_timeout.rb
Qingyu Zhao b7ea4bd853 Enable puma by default in GDK
Two changes:
1. Move bin/web to bin/web_unicorn(removed PUMA switching logic)
Introduce new shadow script bin/web. Now we have 3 scripts working
together: bin/web, bin/web_puma, bin/web_unicorn

  In bin/web, it checks ENV['USE_WEB_SERVER']:
    - if value is 'puma' or value is not set, call bin/web_puma
    - if value is 'unicorn', call bin/web_unicorn
    - report error if other values given

2. Gitlab rails allow ENV setting to override timeout
    - ENV['GITLAB_RAILS_RACK_TIMEOUT'] for service_timeout
    - ENV['GITLAB_RAILS_WAIT_TIMEOUT'] for wait_timeout
2019-07-09 23:31:32 +10:00

23 lines
1.1 KiB
Ruby

# frozen_string_literal: true
# Unicorn terminates any request which runs longer than 60 seconds.
# Puma doesn't have any timeout mechanism for terminating long-running
# requests, to make sure that server is not paralyzed by long-running
# or stuck queries, we add a request timeout which terminates the
# request after 60 seconds. This may be dangerous in some situations
# (https://github.com/heroku/rack-timeout/blob/master/doc/exceptions.md)
# and it's used only as the last resort. In such case this termination is
# logged and we should fix the potential timeout issue in the code itself.
if defined?(::Puma) && !Rails.env.test?
require 'rack/timeout/base'
Gitlab::Application.configure do |config|
config.middleware.insert_before(Rack::Runtime, Rack::Timeout,
service_timeout: ENV.fetch('GITLAB_RAILS_RACK_TIMEOUT', 60).to_i,
wait_timeout: ENV.fetch('GITLAB_RAILS_WAIT_TIMEOUT', 90).to_i)
end
observer = Gitlab::Cluster::RackTimeoutObserver.new
Rack::Timeout.register_state_change_observer(:gitlab_rack_timeout, &observer.callback)
end