Skip to content

Commit 594fc16

Browse files
authored
GH-46236: [Release][Packaging] Fix dev/release/post-03-binary.sh errors (#46237)
### Rationale for this change There are two problems: `with_read_timeout` can't set timeout: /host/binary-task.rb:463:in `with_read_timeout': undefined method `read_timeout' for nil:NilClass (NoMethodError) current_timeout = @ http.read_timeout ^^^^^^^^^^^^^ from /host/binary-task.rb:680:in `block in copy' from /host/binary-task.rb:442:in `with_retry' from /host/binary-task.rb:679:in `copy' from /host/binary-task.rb:1100:in `block (3 levels) in release' from /host/binary-task.rb:746:in `pull' from /host/binary-task.rb:1099:in `block (2 levels) in release' from /host/binary-task.rb:48:in `block (3 levels) in initialize' from /host/binary-task.rb:45:in `loop' from /host/binary-task.rb:45:in `block (2 levels) in initialize' `yum:release` can't download a distribution: ArgumentError: wrong number of arguments (given 3, expected 4) /host/binary-task.rb:1266:in `download_distribution' /host/binary-task.rb:2129:in `block (3 levels) in define_yum_release_tasks' /host/binary-task.rb:2124:in `each' /host/binary-task.rb:2124:in `block (2 levels) in define_yum_release_tasks' ### What changes are included in this PR? * Defer timeout set timing for `with_read_timeout` * Add missing `type` argument for `yum:release` ### Are these changes tested? Yes. I used this for 20.0.0. ### Are there any user-facing changes? No. * GitHub Issue: #46236 Authored-by: Sutou Kouhei <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
1 parent 1807297 commit 594fc16

File tree

1 file changed

+34
-27
lines changed

1 file changed

+34
-27
lines changed

dev/release/binary-task.rb

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ def initialize(request, response, message)
268268

269269
def initialize
270270
@http = nil
271+
@current_timeout = nil
271272
end
272273

273274
private def start_http(url, &block)
@@ -302,32 +303,38 @@ def request(method, headers, url, body: nil, &block)
302303
end
303304

304305
private def request_internal(http, request, &block)
305-
http.request(request) do |response|
306-
case response
307-
when Net::HTTPSuccess,
308-
Net::HTTPNotModified
309-
if block_given?
310-
return yield(response)
306+
read_timeout = http.read_timeout
307+
begin
308+
http.read_timeout = @current_timeout if @current_timeout
309+
http.request(request) do |response|
310+
case response
311+
when Net::HTTPSuccess,
312+
Net::HTTPNotModified
313+
if block_given?
314+
return yield(response)
315+
else
316+
response.read_body
317+
return response
318+
end
319+
when Net::HTTPRedirection
320+
redirected_url = URI(response["Location"])
321+
redirected_request = Net::HTTP::Get.new(redirected_url, {})
322+
start_http(redirected_url) do |redirected_http|
323+
request_internal(redirected_http, redirected_request, &block)
324+
end
311325
else
312-
response.read_body
313-
return response
314-
end
315-
when Net::HTTPRedirection
316-
redirected_url = URI(response["Location"])
317-
redirected_request = Net::HTTP::Get.new(redirected_url, {})
318-
start_http(redirected_url) do |redirected_http|
319-
request_internal(redirected_http, redirected_request, &block)
320-
end
321-
else
322-
message = "failed to request: "
323-
message << "#{request.uri}: #{request.method}: "
324-
message << "#{response.message} #{response.code}"
325-
if response.body
326-
message << "\n"
327-
message << response.body
326+
message = "failed to request: "
327+
message << "#{request.uri}: #{request.method}: "
328+
message << "#{response.message} #{response.code}"
329+
if response.body
330+
message << "\n"
331+
message << response.body
332+
end
333+
raise Error.new(request, response, message)
328334
end
329-
raise Error.new(request, response, message)
330335
end
336+
ensure
337+
http.read_timeout = read_timeout
331338
end
332339
end
333340

@@ -460,12 +467,11 @@ def with_retry(max_n_retries, target)
460467
end
461468

462469
def with_read_timeout(timeout)
463-
current_timeout = @http.read_timeout
470+
current_timeout, @current_timeout = @current_timeout, timeout
464471
begin
465-
@http.read_timeout = timeout
466472
yield
467473
ensure
468-
@http.read_timeout = current_timeout
474+
@current_timeout = current_timeout
469475
end
470476
end
471477
end
@@ -2125,7 +2131,8 @@ def define_yum_release_tasks
21252131
list: uploaded_files_name)
21262132

21272133
distribution_dir = "#{yum_release_repositories_dir}/#{distribution}"
2128-
download_distribution(distribution,
2134+
download_distribution(:artifactory,
2135+
distribution,
21292136
distribution_dir,
21302137
:rc,
21312138
pattern: /\/repodata\//)

0 commit comments

Comments
 (0)