Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[#52921] Configure HTTPX timeouts.

Pavel Balashou36e0450c1466
diff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rb
index 0c278d7fdd3..054a9266c24 100644
--- a/config/constants/settings/definition.rb
+++ b/config/constants/settings/definition.rb
@@ -716,6 +716,34 @@ module Settings
format: :string,
default: nil
},
+ httpx_connect_timeout: {
+ description: '',
+ format: :float,
+ writable: false,
+ allowed: (0..),
+ default: 3
+ },
+ httpx_read_timeout: {
+ description: '',
+ format: :float,
+ writable: false,
+ allowed: (0..),
+ default: 3
+ },
+ httpx_write_timeout: {
+ description: '',
+ format: :float,
+ writable: false,
+ allowed: (0..),
+ default: 3
+ },
+ httpx_keep_alive_timeout: {
+ description: '',
+ format: :float,
+ writable: false,
+ allowed: (0..),
+ default: 20
+ },
rate_limiting: {
default: {},
description: 'Configure rate limiting for various endpoint rules. See configuration documentation for details.'
@@ -833,7 +861,7 @@ module Settings
sendmail_arguments: {
description: 'Arguments to call sendmail with in case it is configured as outgoing email setup',
format: :string,
- default: "-i",
+ default: "-i"
},
sendmail_location: {
description: 'Location of sendmail to call if it is configured as outgoing email setup',
diff --git a/lib/open_project.rb b/lib/open_project.rb
index 75072711fd6..f3518182137 100644
--- a/lib/open_project.rb
+++ b/lib/open_project.rb
@@ -33,6 +33,7 @@ require 'open_project/logging'
require 'open_project/patches'
require 'open_project/mime_type'
require 'open_project/custom_styles/design'
+require 'open_project/httpx_appsignal'
require 'redmine/plugin'
require 'csv'
@@ -46,8 +47,23 @@ module OpenProject
end
def self.httpx
- HTTPX
- .plugin(:basic_auth)
- .plugin(:webdav)
+ # It is essential to reuse HTTPX session if persistent connections are enabled.
+ # Otherwise for every request there will be a new connections.
+ # And old connections will not be closed properly which could lead to EMFILE error.
+ Thread.current[:httpx_session] ||= begin
+ session = HTTPX
+ .plugin(:persistent) # persistent plugin enables retries plugin under the hood
+ .plugin(:basic_auth)
+ .plugin(:webdav)
+ .with(
+ timeout: {
+ connect_timeout: OpenProject::Configuration.httpx_connect_timeout,
+ write_timeout: OpenProject::Configuration.httpx_write_timeout,
+ read_timeout: OpenProject::Configuration.httpx_read_timeout,
+ keep_alive_timeout: OpenProject::Configuration.httpx_keep_alive_timeout
+ }
+ )
+ OpenProject::Appsignal.enabled? ? session.plugin(HttpxAppsignal) : session
+ end
end
end
diff --git a/lib/open_project/httpx_appsignal.rb b/lib/open_project/httpx_appsignal.rb
new file mode 100644
index 00000000000..3d1b24238fc
--- /dev/null
+++ b/lib/open_project/httpx_appsignal.rb
@@ -0,0 +1,50 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module OpenProject
+ module HttpxAppsignal
+ module ConnectionMethods
+ def send(request)
+ request.on(:response) do
+ # Attention. Errors in this block are suppressed.
+ # When modifying make sure it works.
+ # Otherwise there will be no information sent to AppSignal
+ event = [
+ "request.httpx", # event_group.event_name
+ "#{request.verb.upcase} #{request.uri}", # title
+ nil, # body
+ ::Appsignal::EventFormatter::DEFAULT # formatter
+ ]
+ ::Appsignal::Transaction.current.finish_event(*event)
+ end
+ ::Appsignal::Transaction.current.start_event
+ super
+ end
+ end
+ end
+end
diff --git a/modules/storages/app/workers/storages/manage_nextcloud_integration_cron_job.rb b/modules/storages/app/workers/storages/manage_nextcloud_integration_cron_job.rb
index 0c9fdbdb87a..9fdebaf62d4 100644
--- a/modules/storages/app/workers/storages/manage_nextcloud_integration_cron_job.rb
+++ b/modules/storages/app/workers/storages/manage_nextcloud_integration_cron_job.rb
@@ -34,7 +34,7 @@ module Storages
queue_with_priority :low
- self.cron_expression = '*/5 * * * *'
+ self.cron_expression = '1 * * * *'
def self.ensure_scheduled!
if ::Storages::ProjectStorage.active_automatically_managed.exists?
diff --git a/modules/storages/spec/contracts/storages/storages/nextcloud_contract_spec.rb b/modules/storages/spec/contracts/storages/storages/nextcloud_contract_spec.rb
index 0f9d11b461c..7f2bac5af98 100644
--- a/modules/storages/spec/contracts/storages/storages/nextcloud_contract_spec.rb
+++ b/modules/storages/spec/contracts/storages/storages/nextcloud_contract_spec.rb
@@ -93,8 +93,8 @@ RSpec.describe Storages::Storages::NextcloudContract, :storage_server_helpers, :
expect(subject.errors.to_hash)
.to eq({ password: ["could not be validated. Please check your storage connection and try again."] })
- # will be twice when httpx persistent plugin enabled.
- expect(credentials_request).to have_been_made.once
+ # twice due to HTTPX retry plugin being enabled.
+ expect(credentials_request).to have_been_made.twice
end
end
diff --git a/modules/storages/spec/contracts/storages/storages/shared_contract_examples.rb b/modules/storages/spec/contracts/storages/storages/shared_contract_examples.rb
index a418d55e205..ab76b554539 100644
--- a/modules/storages/spec/contracts/storages/storages/shared_contract_examples.rb
+++ b/modules/storages/spec/contracts/storages/storages/shared_contract_examples.rb
@@ -192,8 +192,8 @@ RSpec.shared_examples_for 'nextcloud storage contract', :storage_server_helpers,
it 'retries failed request once' do
contract.validate
- # will be twice when httpx persistent plugin enabled.
- expect(stub_server_capabilities).to have_been_made.once
+ # twice due to HTTPX retry plugin being enabled.
+ expect(stub_server_capabilities).to have_been_made.twice
end
end
@@ -205,8 +205,8 @@ RSpec.shared_examples_for 'nextcloud storage contract', :storage_server_helpers,
it 'retries failed request once' do
contract.validate
- # will be twice when httpx persistent plugin enabled.
- expect(stub_config_check).to have_been_made.once
+ # twice due to HTTPX retry plugin being enabled.
+ expect(stub_config_check).to have_been_made.twice
end
end
end
diff --git a/modules/storages/spec/workers/storages/manage_nextcloud_integration_cron_job_spec.rb b/modules/storages/spec/workers/storages/manage_nextcloud_integration_cron_job_spec.rb
index 0548e9f4e2a..689dbb1a096 100644
--- a/modules/storages/spec/workers/storages/manage_nextcloud_integration_cron_job_spec.rb
+++ b/modules/storages/spec/workers/storages/manage_nextcloud_integration_cron_job_spec.rb
@@ -33,7 +33,7 @@ require_module_spec_helper
RSpec.describe Storages::ManageNextcloudIntegrationCronJob, :webmock, type: :job do
it 'has a schedule set' do
- expect(described_class.cron_expression).to eq('*/5 * * * *')
+ expect(described_class.cron_expression).to eq('1 * * * *')
end
describe '.ensure_scheduled!' do