Skip to content

Commit 8071686

Browse files
pablomhclaude
andcommitted
Fixes #39229 - Add foreman_request_timeout setting to control Net::HTTP read timeout
ForemanRequest uses a bare Net::HTTP instance whose read_timeout defaults to Ruby's hardcoded 60s. Under high-concurrency registration load this causes 500 errors when Foreman takes longer than 60s to process POST /register. Introduces :foreman_request_timeout (documented in settings.yml.example) and applies it to http.read_timeout in ForemanRequest#http_init when configured. The respond_to? guard preserves backward compatibility when the setting is absent. subscription-manager's default server_timeout is 180s, so values above that are recommended to avoid cutting connections the client is still waiting on. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent a5780bc commit 8071686

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

config/settings.yml.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
#:foreman_ssl_cert: ssl/certs/fqdn.pem
4343
#:foreman_ssl_key: ssl/private_keys/fqdn.pem
4444

45+
# Timeout in seconds for HTTP requests from smart-proxy to Foreman (e.g. POST /register).
46+
# Defaults to Ruby's Net::HTTP read timeout (60s) when unset. Consider raising this
47+
# above your client's timeout to avoid cutting connections the client is still waiting on.
48+
# subscription-manager's default server_timeout is 180s, so a value above that is recommended.
49+
#:foreman_request_timeout: 60
50+
4551
# host and ports configuration
4652
# an array of interfaces to bind ports to (possible values: *, localhost, 0.0.0.0)
4753
#:bind_host: ['*']

lib/proxy/request.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ def http_init
6666
http = Net::HTTP.new(uri.host, uri.port)
6767
http.use_ssl = uri.scheme == 'https'
6868
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
69+
if Proxy::SETTINGS.foreman_request_timeout.to_i > 0
70+
http.read_timeout = Proxy::SETTINGS.foreman_request_timeout.to_i
71+
end
6972

7073
if http.use_ssl?
7174
ca_file = Proxy::SETTINGS.foreman_ssl_ca || Proxy::SETTINGS.ssl_ca_file

test/request_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ def test_post
5454
assert_equal("body", result.body)
5555
end
5656

57+
def test_read_timeout_applied_when_foreman_request_timeout_configured
58+
Proxy::SETTINGS.stubs(:foreman_request_timeout).returns(120)
59+
request = Proxy::HttpRequest::ForemanRequest.new
60+
assert_equal 120, request.http.read_timeout
61+
end
62+
63+
def test_read_timeout_uses_default_when_foreman_request_timeout_not_configured
64+
default_timeout = Net::HTTP.new('example.com').read_timeout
65+
request = Proxy::HttpRequest::ForemanRequest.new
66+
assert_equal default_timeout, request.http.read_timeout
67+
end
68+
5769
def test_post_with_nested_params
5870
stub_request(:post, @foreman_url + '/register?activation_keys%5B%5D=ac_AlmaLinux8&location_id=2&organization_id=1&repo_data%5B%5D%5Brepo%5D=repo1&repo_data%5B%5D%5Brepo_gpg_key_url%5D=key1&repo_data%5B%5D%5Brepo%5D=repo2&repo_data%5B%5D%5Brepo_gpg_key_url%5D=key2&update_packages=false')
5971
.to_return(status: 200, body: "body", headers: {h1: "header"})

0 commit comments

Comments
 (0)