Commit b1512038 authored by Tiago Botelho's avatar Tiago Botelho

Adds dynamic timeout to list_new_blobs Gitaly call

parent cda6f2e8
......@@ -42,7 +42,7 @@ module EE
logger.log_timed(LOG_MESSAGES[__method__]) do
max_file_size = push_rule.max_file_size
blobs = project.repository.new_blobs(newrev)
blobs = project.repository.new_blobs(newrev, dynamic_timeout: logger.time_left)
large_blob = blobs.find do |blob|
::Gitlab::Utils.bytes_to_megabytes(blob.size) > max_file_size
......
......@@ -326,12 +326,12 @@ module Gitlab
end
end
def new_blobs(newrev)
def new_blobs(newrev, dynamic_timeout: nil)
return [] if newrev.blank? || newrev == ::Gitlab::Git::BLANK_SHA
strong_memoize("new_blobs_#{newrev}") do
wrapped_gitaly_errors do
gitaly_ref_client.list_new_blobs(newrev, REV_LIST_COMMIT_LIMIT)
gitaly_ref_client.list_new_blobs(newrev, REV_LIST_COMMIT_LIMIT, dynamic_timeout: dynamic_timeout)
end
end
end
......
......@@ -82,15 +82,22 @@ module Gitlab
commits
end
def list_new_blobs(newrev, limit = 0)
def list_new_blobs(newrev, limit = 0, dynamic_timeout: nil)
request = Gitaly::ListNewBlobsRequest.new(
repository: @gitaly_repo,
commit_id: newrev,
limit: limit
)
timeout =
if dynamic_timeout
[dynamic_timeout, GitalyClient.medium_timeout].min
else
GitalyClient.medium_timeout
end
response = GitalyClient
.call(@storage, :ref_service, :list_new_blobs, request, timeout: GitalyClient.medium_timeout)
.call(@storage, :ref_service, :list_new_blobs, request, timeout: timeout)
response.flat_map do |msg|
# Returns an Array of Gitaly::NewBlobObject objects
......
......@@ -89,6 +89,16 @@ describe Gitlab::GitalyClient::RefService do
end
end
describe '#list_new_blobs' do
it 'raises DeadlineExceeded when timeout is too small' do
newrev = '54fcc214b94e78d7a41a9a8fe6d87a5e59500e51'
expect do
client.list_new_blobs(newrev, dynamic_timeout: 0.001)
end.to raise_error(GRPC::DeadlineExceeded)
end
end
describe '#local_branches' do
it 'sends a find_local_branches message' do
expect_any_instance_of(Gitaly::RefService::Stub)
......
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