summaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorJan Provaznik <jprovaznik@gitlab.com>2019-05-29 18:53:44 +0000
committerMayra Cabrera <mcabrera@gitlab.com>2019-05-29 18:53:44 +0000
commit6d6bae66dffefeb3f34f2646b0e801b3c1002170 (patch)
tree3f9d88e2b1282418b1e011465d9c4ab6bc50cca4 /config
parent70d1537dda66da8b319ceefde36195047b26a8fd (diff)
downloadgitlab-ce-6d6bae66dffefeb3f34f2646b0e801b3c1002170.tar.gz
Added rack-timeout for Puma
It assures that requests are aborted after 60 seconds, otherwise an exception is raised. This exception is logged by Sentry, also there is a Prometheus counter for measuring number of requests in each state.
Diffstat (limited to 'config')
-rw-r--r--config/initializers/rack_timeout.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/config/initializers/rack_timeout.rb b/config/initializers/rack_timeout.rb
new file mode 100644
index 00000000000..5c4f2dd708c
--- /dev/null
+++ b/config/initializers/rack_timeout.rb
@@ -0,0 +1,23 @@
+# 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: 60,
+ wait_timeout: 90)
+ end
+
+ observer = Gitlab::RackTimeoutObserver.new
+ Rack::Timeout.register_state_change_observer(:gitlab_rack_timeout, &observer.callback)
+end