@@ -367,6 +367,7 @@ def execute_streaming(request, options: {}, &block)
367
367
apply_auth ( request , basic_auth ) if redirects . zero?
368
368
369
369
# don't call return within the `request` block
370
+ close_and_sleep = nil
370
371
http . request ( request ) do |nethttp |
371
372
response = Puppet ::HTTP ::ResponseNetHTTP . new ( request . uri , nethttp )
372
373
begin
@@ -380,12 +381,14 @@ def execute_streaming(request, options: {}, &block)
380
381
interval = @retry_after_handler . retry_after_interval ( request , response , retries )
381
382
retries += 1
382
383
if interval
383
- if http . started?
384
- Puppet . debug ( "Closing connection for #{ Puppet ::HTTP ::Site . from_uri ( request . uri ) } " )
385
- http . finish
384
+ close_and_sleep = proc do
385
+ if http . started?
386
+ Puppet . debug ( "Closing connection for #{ Puppet ::HTTP ::Site . from_uri ( request . uri ) } " )
387
+ http . finish
388
+ end
389
+ Puppet . warning ( _ ( "Sleeping for %{interval} seconds before retrying the request" ) % { interval : interval } )
390
+ ::Kernel . sleep ( interval )
386
391
end
387
- Puppet . warning ( _ ( "Sleeping for %{interval} seconds before retrying the request" ) % { interval : interval } )
388
- ::Kernel . sleep ( interval )
389
392
next
390
393
end
391
394
end
@@ -404,6 +407,10 @@ def execute_streaming(request, options: {}, &block)
404
407
405
408
done = true
406
409
end
410
+ ensure
411
+ # If a server responded with a retry, make sure the connection is closed and then
412
+ # sleep the specified time.
413
+ close_and_sleep . call if close_and_sleep
407
414
end
408
415
end
409
416
0 commit comments