Commit e07469ff authored by Jacob Vosmaer's avatar Jacob Vosmaer

Use an HTTP timeout of 5 minutes by default

parent 82b3a4e8
...@@ -17,6 +17,7 @@ gitlab_url: "http://localhost:8080" ...@@ -17,6 +17,7 @@ gitlab_url: "http://localhost:8080"
# See installation.md#using-https for additional HTTPS configuration details. # See installation.md#using-https for additional HTTPS configuration details.
http_settings: http_settings:
# read_timeout: 300
# user: someone # user: someone
# password: somepass # password: somepass
# ca_file: /etc/ssl/cert.pem # ca_file: /etc/ssl/cert.pem
......
...@@ -10,6 +10,9 @@ require_relative 'httpunix' ...@@ -10,6 +10,9 @@ require_relative 'httpunix'
class GitlabNet class GitlabNet
class ApiUnreachableError < StandardError; end class ApiUnreachableError < StandardError; end
CHECK_TIMEOUT = 5
READ_TIMEOUT = 300
def check_access(cmd, repo, actor, changes) def check_access(cmd, repo, actor, changes)
project_name = repo.gsub("'", "") project_name = repo.gsub("'", "")
project_name = project_name.gsub(/\.git\Z/, "") project_name = project_name.gsub(/\.git\Z/, "")
...@@ -50,7 +53,7 @@ class GitlabNet ...@@ -50,7 +53,7 @@ class GitlabNet
end end
def check def check
get("#{host}/check") get("#{host}/check", read_timeout: CHECK_TIMEOUT)
end end
protected protected
...@@ -63,13 +66,15 @@ class GitlabNet ...@@ -63,13 +66,15 @@ class GitlabNet
"#{config.gitlab_url}/api/v3/internal" "#{config.gitlab_url}/api/v3/internal"
end end
def http_client_for(uri) def http_client_for(uri, options={})
if uri.is_a?(URI::HTTPUNIX) if uri.is_a?(URI::HTTPUNIX)
http = Net::HTTPUNIX.new(uri.hostname) http = Net::HTTPUNIX.new(uri.hostname)
else else
http = Net::HTTP.new(uri.host, uri.port) http = Net::HTTP.new(uri.host, uri.port)
end end
http.read_timeout = options[:read_timeout] || READ_TIMEOUT
if uri.is_a?(URI::HTTPS) if uri.is_a?(URI::HTTPS)
http.use_ssl = true http.use_ssl = true
http.cert_store = cert_store http.cert_store = cert_store
...@@ -92,12 +97,12 @@ class GitlabNet ...@@ -92,12 +97,12 @@ class GitlabNet
request request
end end
def request(method, url, params = {}) def request(method, url, params = {}, options={})
$logger.debug "Performing #{method.to_s.upcase} #{url}" $logger.debug "Performing #{method.to_s.upcase} #{url}"
uri = URI.parse(url) uri = URI.parse(url)
http = http_client_for(uri) http = http_client_for(uri, options)
request = http_request_for(method, uri, params) request = http_request_for(method, uri, params)
begin begin
...@@ -116,8 +121,8 @@ class GitlabNet ...@@ -116,8 +121,8 @@ class GitlabNet
response response
end end
def get(url) def get(url, options={})
request(:get, url) request(:get, url, {}, options)
end end
def post(url, params) def post(url, params)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment