13697: Set Rails database timeout to API.RequestTimeout config.
authorTom Clegg <tom@curii.com>
Wed, 22 Sep 2021 20:57:57 +0000 (16:57 -0400)
committerTom Clegg <tom@curii.com>
Wed, 22 Sep 2021 20:57:57 +0000 (16:57 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

services/api/config/arvados_config.rb
services/api/config/initializers/db_timeout.rb [new file with mode: 0644]

index ea421a289b98cc628d6bfa9b0473a105a2986b0c..49865039c4649a8a8b7270682b97fd073b742504 100644 (file)
@@ -84,6 +84,7 @@ arvcfg.declare_config "API.MaxRequestSize", Integer, :max_request_size
 arvcfg.declare_config "API.MaxIndexDatabaseRead", Integer, :max_index_database_read
 arvcfg.declare_config "API.MaxItemsPerResponse", Integer, :max_items_per_response
 arvcfg.declare_config "API.MaxTokenLifetime", ActiveSupport::Duration
+arvcfg.declare_config "API.RequestTimeout", ActiveSupport::Duration
 arvcfg.declare_config "API.AsyncPermissionsUpdateInterval", ActiveSupport::Duration, :async_permissions_update_interval
 arvcfg.declare_config "Users.AutoSetupNewUsers", Boolean, :auto_setup_new_users
 arvcfg.declare_config "Users.AutoSetupNewUsersWithVmUUID", String, :auto_setup_new_users_with_vm_uuid
diff --git a/services/api/config/initializers/db_timeout.rb b/services/api/config/initializers/db_timeout.rb
new file mode 100644 (file)
index 0000000..3b61f15
--- /dev/null
@@ -0,0 +1,9 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
+ActiveRecord::ConnectionAdapters::AbstractAdapter.set_callback :checkout, :before, ->(conn) do
+  ms = Rails.configuration.API.RequestTimeout.to_i * 1000
+  conn.execute("SET statement_timeout = #{ms}")
+  conn.execute("SET lock_timeout = #{ms}")
+end